【发布时间】:2022-11-02 16:55:07
【问题描述】:
我有一个类似于以下内容的数据框:
df = pd.DataFrame({
'employee_id' : [123, 456, 789],
'country_code' : ['US', 'CAN', 'MEX'],
'comments' : (['good performer', 'due for raise', 'should be promoted'],
['bad performer', 'should be fired', 'speak to HR'],
['recently hired', 'needs training', 'shows promise'])
})
df
employee_id country_code comments
0 123 US [good performer, due for raise, should be promoted]
1 456 CAN [bad performer, should be fired, speak to HR]
2 789 MEX [recently hired, needs training, shows promise]
我希望能够将comments 列过滤为删除任何行包含字符串'performer'。为此,我正在使用:
df = df[~df['comments'].str.contains('performer')]
但是,这会返回一个错误:
TypeError: ufunc 'invert' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
提前感谢您提供的任何帮助!
【问题讨论】:
标签: pandas