Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试扫描数据框中的特定列,例如df['x']我在单独列表中的值list = ['y', 'z', 'a', 'b']。df['x']如果包含列表中的任何值或多个值,如何使熊猫加载具有列表值的新列?
df['x']
list = ['y', 'z', 'a', 'b']
谢谢!
用这个:
In [720]: import pandas as pd In [719]: if df['x'].str.contains('|'.join(list)).any(): ...: df = pd.concat([df, pd.DataFrame(list)], axis=1)) ...: