【发布时间】:2016-12-16 04:46:42
【问题描述】:
我有一个数据框 df 如下,我想删除或删除名称为 tom 的行,我使用以下代码(python3):
df1[~df1['name'].str.contains('tom')]
但有错误:
AttributeError: Cannot access attribute 'str' of 'SeriesGroupBy'
objects, try using the 'apply' method
name age weight
tom 10 40
lucy 15 50
john 20 60
tom 10 40
lucy 15 50
john 20 60
tom 10 40
kate 30 70
tick 40 75
bruce 50 75
请帮我解决,这只是示例数据,因为真实的数据框很大。如果你们有快速的解决方案,请告诉我。提前致谢!
【问题讨论】:
-
错误是说
df1是SeriesGroupBy对象,而不是DataFrame。显然,具有name、age、weight列的 DataFrame 不是df1。
标签: pandas dataframe python-3.5