熊猫str。包含列表吗?

时间:2018-08-02 16:08:19

标签: python python-3.x pandas dataframe

我使用类似以下的内容来更新我的数据框

function runScript() {
  while (!err) {
    // do stuff
    wait(5 seconds - however long 'do stuff' took) // if it took 1 second to 'do stuff', then it waits 4 seconds
  }
}

runScript()

但是当我的系列包含df.loc[(df['Message'].str.contains('hello', case=False)),'SomeSeries'] = 'SomeUpdate' 'hello''bicycle'等时,我可能想更新。 显然,我可以遍历一个列表,但是我想知道是否有一种方法可以在一行中执行此操作?我想要类似的东西

'monday'

1 个答案:

答案 0 :(得分:1)

您需要

 df.loc[(df['Message'].str.contains('|'.join(watchlist), case=False)),'SomeSeries'] = 'SomeUpdate'
相关问题