【发布时间】:2018-03-15 12:34:42
【问题描述】:
我有一个数据框,
DF,
Name Stage Description
Sri 1 Sri is one of the good singer in this two
2 Thanks for reading
Ram 1 Ram is one of the good cricket player
ganesh 1 good driver
还有一个列表,
my_list=["one"]
I tried mask=df["Description"].str.contains('|'.join(my_list),na=False)
但它给了,
output_DF.
Name Stage Description
Sri 1 Sri is one of the good singer in this two
Ram 1 Ram is one of the good cricket player
My desired output is,
desired_DF,
Name Stage Description
Sri 1 Sri is one of the good singer in this two
2 Thanks for reading
Ram 1 Ram is one of the good cricket player
它必须考虑阶段列,我想要与描述相关的所有行。
【问题讨论】:
-
print (df.index)是什么? -
不,mask=df["Description"].str.contains(my_list,na=False) 效果很好,但我也想选择另一行。直到阶段结束或阶段再次为 1
-
我的电脑挂了 重启和回答,给我一些时间。
-
Name列是否可能匹配数据? -
否,见阶段 =2 ,名称列为空
标签: python regex pandas dataframe data-analysis