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')]
?