Pandas: How to find a particular pattern in a dataframe column?

前端 未结 4 1422
臣服心动
臣服心动 2020-12-03 09:23

I\'d like to find a particular pattern in a pandas dataframe column, and return the corresponding index values in order to subset the dataframe.

Here\'s a sample dat

4条回答
  •  没有蜡笔的小新
    2020-12-03 09:45

    for col in df:
        index = df[col][(df[col] == pattern[0]) & (df[col].shift(-1) == pattern[1]) & (df[col].shift(-2) == pattern[2])].index
        if not index.empty: print(index)
    

提交回复
热议问题