python pandas直方图包括NaN值

Har*_*ari 9 python pandas

我想绘制一些数据的直方图.抱歉我无法附上样本直方图,因为我没有足够的声誉.希望你能理解我对我面临的问题的描述.我正在使用python pandas,我意识到任何NaN值都被pandas视为0.有没有什么方法可以用来在直方图中包含Nan值的计数?我的意思是x轴也应该具有NaN值.请帮忙......非常感谢.

Mon*_*iks 4

我一直在寻找同样的东西。我最终得到了以下解决方案:

figure = plt.figure(figsize=(6,9), dpi=100);    
graph = figure.add_subplot(111);

freq = pandas.value_counts(data)
bins = freq.index
x=graph.bar(bins, freq.values) #gives the graph without NaN

graphmissing = figure.add_subplot(111)
y = graphmissing.bar([0], freq[numpy.NaN]) #gives a bar for the number of missing values at x=0

figure.show()
Run Code Online (Sandbox Code Playgroud)

这给了我一个直方图,其中 0 处的一列显示数据中缺失值的数量。