首页 > 解决方案 > 如何从 Windows 中的数据框中删除整行?

问题描述

avg_ratings = ratings.groupby ('movieId').mean()

del avg_ratings = ('movieId')

avg_ratings.head()

File "<ipython-input-13-9ecfb8af04ef>", line 3
del avg_ratings = ('movieId')
SyntaxError: invalid syntax

标签: pythonpandasdataframejupyter

解决方案


如果您知道要删除的行的索引,请使用drop() 函数,例如。G:

rows_to_remove = [1, 2, 3]
df.drop(index=rows_to_remove, inplace=True)

推荐阅读