Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 一列中有多个字符串匹配_Python_Pandas - Fatal编程技术网

Python 一列中有多个字符串匹配

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()

您好,我正在使用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()
将类型从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