pandas python中的熊猫直方图。可以用概率/密度代替计数吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25577317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pandas histogram in python. possible to make probability/density instead of count?
提问by wolfsatthedoor
Histogram in pandas plots the count of each bin, rather than the normalized fraction. In R, this is an option in the histogram. Is it possible in Pandas? If not, any recommendations for an easy workaround?
pandas 中的直方图绘制了每个 bin 的计数,而不是归一化的分数。在 R 中,这是直方图中的一个选项。在Pandas中可能吗?如果没有,是否有任何简单解决方法的建议?
回答by BKay
For me this gives the desired results.
对我来说,这给出了想要的结果。
df = pd.DataFrame(np.random.randn(5000))
df.hist(normed = True)
The 'density' option works in numpy's histogram function but not on pandas's hist function.
'密度' 选项适用于 numpy 的直方图函数,但不适用于 Pandas 的 hist 函数。
回答by K.Chen
You can pass density parameter to hist, like this
您可以将密度参数传递给 hist,就像这样
df.hist(..., density=True)
Here, density is passed as kwds to np.hist.
这里,密度作为 kwds 传递给 np.hist。
Reference: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.hist.htmlhttp://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html
参考:http: //pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.hist.html http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html

