简体   繁体   English

从条形图 matplotlib 中删除 nan 值

[英]Removing nan values from bar graph matplotlib

I'm trying to remove nan values from showing up on the tail end of my bar graph, this is my code reading from a csv stored in scorecard我正在尝试从条形图尾部显示的 nan 值中删除,这是我从scorecard存储的 csv 读取的代码

errors = scorecard.Errors
y_pos = np.arange(len(errors))
total = scorecard.Total

plt.bar(y_pos, total, align='center')
plt.xticks(y_pos, errors)
plt.xticks(rotation=45)

which displays this:显示这个: 在此处输入图片说明

dropna removes more data than I would like. dropna 删除的数据比我想要的多。

I tried adding a simple plt.plot() at the end of the block at it got rid of the two nan我尝试在块的末尾添加一个简单的plt.plot()去掉了两个nan

If you are using pandas lib to read the csv, you can use the function dropna() like the documentation.如果您使用 pandas lib 读取 csv,则可以像文档一样使用dropna()函数。 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html

Using like this像这样使用

scorecard.dropna()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM