首页 > 解决方案 > 无法绘制熊猫系列的直方图

问题描述

我是一个 Python 新手,不知何故我无法在我的数据框中获得一个简单的柱状图。这是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

我试过了:

df['col'].hist(bins=10)
plt.plot()

这导致: 在此处输入图像描述

一些建议使用它的解决方案np.histogram(...),但这并不自然。

实际上,一个 bin 大小,例如 1000 和一个 bin 中超过 10000 的所有内容都会很好。

谢谢,我会很感激一个提示。

标签: pythonpandas

解决方案


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()

推荐阅读