pandas 直方图忽略无效数据;限制x范围 [英] Pandas histogram ignoring invalid data; limit x-range

查看:89
本文介绍了 pandas 直方图忽略无效数据;限制x范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,其中包含文本和数字数据,其中一些-999值表示丢失或无效的数据.作为一个玩具示例,让我们说它看起来像这样:

I have a dataframe which consists of a mix of text and numerical data, with some values of -999 representing missing or invalid data. As a toy example, let's say it looks like this:

import pandas as pd
import matplotlib.pyplot as plt

dictOne = {'Name':['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth'],
           "A":[1, 2, -3, 4, 5, -999, 7, -999, 9],
           "B":[4, 5, 6, 5, 3, -999, 2, 9, 5],
           "C":[7, -999, 10, 5, 8, 6, 8, 2, 4]}
df2 = pd.DataFrame(dictOne)

df2.hist('C', bins = 1000)
plt.xlim=([0, 10])

这给

我正在尝试排除-999值.熊猫有没有简单的方法可以做到这一点?

I'm trying to exclude the -999 values. Is there an easy way in Pandas to do this?

在我的示例代码中,为什么x轴不限于[0,10]范围?

Also, in my example code, why the x-axis not limited to the range [0,10]?

推荐答案

df2[df2['C'] > -999].hist('C')可以满足您的所有目的.无需指定1000个垃圾箱.

df2[df2['C'] > -999].hist('C') will suffice for all of your purposes. Specifying 1000 bins is not necessary.

这篇关于 pandas 直方图忽略无效数据;限制x范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆