Unk*_*der 3 python dataframe python-3.x pandas
我使用类似以下内容来更新我的数据框
df.loc[(df['Message'].str.contains('hello', case=False)),'SomeSeries'] = 'SomeUpdate'
Run Code Online (Sandbox Code Playgroud)
'hello'但当我的系列包含or'bicycle'或等时,我可能想更新。'monday'显然,我可以迭代列表,但我想知道是否有办法在一行中做到这一点?我想要类似的东西
watchlist = ['hello','bicycle','monday']
df.loc[(df['Message'].str.contains(watchlist, case=False)),'SomeSeries'] = 'SomeUpdate'
Run Code Online (Sandbox Code Playgroud)
你需要,
df.loc[(df['Message'].str.contains('|'.join(watchlist), case=False)),'SomeSeries'] = 'SomeUpdate'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2308 次 |
| 最近记录: |