[英]Can't manage to plot a histogram of pandas series
I am a Python newbie and somehow I can not manage to get a simple histogramm of a column in my dataframe.我是 Python 新手,不知怎的,我无法在我的 dataframe 中获得一个简单的柱状图。 This is what df['col'].describe()
returns:这是df['col'].describe()
返回的内容:
count 2.905430e+05
mean 2.732126e+06
std 5.743739e+08
min 3.095194e-03
25% 2.341733e+03
50% 5.092117e+03
75% 1.092925e+04
max 2.089247e+11
Name: avg_power_in_w, dtype: float64
I tried:我试过了:
df['col'].hist(bins=10)
plt.plot()
Some solutions where suggesting it to use np.histogram(...)
, but that does not feel natural.一些建议使用np.histogram(...)
的解决方案,但这并不自然。
Actually a bin size eg 1000 and everything above 10000 in one bin would be nice.实际上,一个 bin 大小,例如 1000 和一个 bin 中超过 10000 的所有内容都会很好。
Thanks, I'd appreciate a hint.谢谢,我会很感激一个提示。
As mentioned in the comments, it seems the like some outliers made the range of values to big.正如评论中提到的,似乎一些异常值使值的范围变大了。 So best practice was所以最佳实践是
#make a copy of the dataframe, so the data keeps untouched
df_copy = df.copy()
#change the values in the column
df.loc[df[col] > 10000] = 10000
#the print it as usual
df['col'].hist(bins=10)
plt.plot()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.