python - 如何从 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
解决方案
如果您知道要删除的行的索引,请使用drop() 函数,例如。G:
rows_to_remove = [1, 2, 3]
df.drop(index=rows_to_remove, inplace=True)
推荐阅读
- python - 为 Pandas DataFrame 中的特定行组合行索引和行值(字符串)
- java - 泛型返回类型方法中的不兼容类型 (Java)
- ios - 即使设置了 CGRect,UIScrollView 中的 UIPageViewController 仍会显示为全屏 - 用户滚动后立即返回正确的帧值
- css - w3.css 从固定页脚下拉
- java - 使用 DSL KStream 到 KTable 转换的 Kafka Tombstoning
- excel - 如何在For循环中计算重复的元素
- javascript - Javascript:启动两个连续等待会产生错误的结果
- parsing - 调试 APL 代码:如何同时使用 `@`(index) 和 `⊢` (right tack)?
- vba - PowerPoint 如何同时运行宏和超链接?
- python - Python在JSON中查找包含在单词/字符串中的单引号