python - 如何从我的熊猫数据框中按索引删除一行以防止它们出现在我的条形图中
问题描述
我正在使用 df.drop 但是当我运行我的代码时,我仍然在我的情节中看到行索引 10 上的“总数”。我想把它去掉。
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv ("https://raw.githubusercontent.com/ryan-j-hope/Shielding-models/master/2020%20Uk%20Population%20By%20Age%20Demographics.csv", encoding='UTF')
df.drop([10])
print(df)
ag = df["Age Group"]
pop = df["Population (%)"]
plt.bar(ag, pop)
plt.show()
解决方案
你不需要括号。此外,您需要就地指定
df.drop(10, inplace=True)
推荐阅读
- c++ - 国际象棋c ++控制台游戏,区分白色和黑色
- javascript - 孤立世界中的访问节点和电子模块
- html - 跳转到 html/css 中的某个位置
- angular - Angular - 如何仅在激活子路由时订阅子路由参数
- angular - Angular 5 全局查询参数
- html - 为什么背景图像在移动设备上不会改变?
- javascript - 如何使用 sweetAlert js 重定向chice 上的警报按钮?
- php - MySQL fetch 查询 PHP
- python - AttributeError:“列表”对象没有属性“isdigit”。有效地指定句子列表中每个单词的 POS?
- python - 两个 json 对象之间的逗号