Python 一列中有多个字符串匹配
您好,我正在使用isin()和pandas查找数据集“条件”列中包含“10”或“小时”的汽车。 我正在使用Python 一列中有多个字符串匹配,python,pandas,Python,Pandas,您好,我正在使用isin()和pandas查找数据集“条件”列中包含“10”或“小时”的汽车。 我正在使用 UScars.isin({'condition':[10, 'hours']}) 但这给了我一个系统错误 SystemError: 'built-in method view of numpy.ndarray object at 0x000001F40BF30EE0' returned a result with an error set. 我使用condition列上的split()
UScars.isin({'condition':[10, 'hours']})
但这给了我一个系统错误
SystemError: 'built-in method view of numpy.ndarray object at 0x000001F40BF30EE0' returned a result with an error set.
我使用condition列上的split()
将类型从str转换为list
我不知道我哪里出错了。任何帮助都将不胜感激
谢谢
您需要使用
|
运算符指定多个字符串匹配
从文档中:
数据帧中的每个元素是否包含在值中
df = pd.DataFrame({'A' : [0,1,2],
'Condition' : ['10 Hours', '20 Hours', '30 Days']})
print(df)
A Condition
0 0 10 Hours
1 1 20 Hours
2 2 30 Days
df[df['Condition'].str.contains('10|Hours')]
A Condition
0 0 10 Hours
1 1 20 Hours