Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.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 过滤数据帧';s字符串值基于它们可能包含的较小字符串_Python_Pandas - Fatal编程技术网

Python 过滤数据帧';s字符串值基于它们可能包含的较小字符串

Python 过滤数据帧';s字符串值基于它们可能包含的较小字符串,python,pandas,Python,Pandas,我有一个带有日志错误消息的数据帧。我们需要的列如下所示: message "System error foo" "System error foo2" "System error foo" "System error foo" "System error foo3" df2 = df[df['message'] == 'System error foo3.'] 我

我有一个带有日志错误消息的数据帧。我们需要的列如下所示:

message
 
"System error foo"  
"System error foo2"    
"System error foo"    
"System error foo"   
"System error foo3"
df2 = df[df['message'] == 'System error foo3.']
我需要统计所有错误消息,不管它们是什么类型的错误

通常,如果我知道一条特定的消息,我会像这样过滤数据帧:

message
 
"System error foo"  
"System error foo2"    
"System error foo"    
"System error foo"   
"System error foo3"
df2 = df[df['message'] == 'System error foo3.']
但是,我如何处理所有只包含“系统错误”的消息以及后面的任何消息呢?我用asterix试过了,但当然不行。是否存在某种python或本机通配符运算符?或者我需要使用正则表达式吗?

您可以使用

你可以用


df[df['message'].str.contains('System error')]
df[df['message'].str.contains('System error')]