【发布时间】:2021-02-11 11:42:52
【问题描述】:
假设我有一个数据框 df 为:
df = pd.DataFrame({'Index': [1, 2, 3, 4, 5],
'Name': ['A', 'B', 100, 'C', 'D'],
'col1': [np.nan, 'bbby', 'cccy', 'dddy', 'EEEEE'],
'col2': ['water', np.nan, 'WATER', 'soil', 'cold air'],
'col3': ['watermelone', 'hot AIR', 'air conditioner', 'drink', 50000],
'Results': [1000, 2000, 3000, 4000, 5000]})
Out
Index Name col1 col2 col3 Results
1 A NaN water watermelone 1000
2 B bbbY NaN hot AIR 2000
3 100 cccY water air conditioner 3000
4 C dddf soil drink 4000
5 D EEEEE cold air 50000 5000
我有一个清单:matches = ['wat','air']
如何选择col1 或col2 或col3 在matches 中包含i 的所有行。
预期输出:
Index Name col1 col2 col3 Results
1 A NaN water watermelone 1000
2 B bbbY NaN hot AIR 2000
3 100 cccY water air conditioner 3000
5 D EEEEE cold air 50000 5000
【问题讨论】:
标签: python pandas dataframe substring