python - 无法绘制熊猫系列的直方图
问题描述
我是一个 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 的所有内容都会很好。
谢谢,我会很感激一个提示。
解决方案
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()
推荐阅读
- autohotkey - 使 GUI 随窗口移动
- dart - 如何在 Dart 中替换 unicode 转义字符
- sql - 如何通过在接下来的 23 天内将日期列增加 1 天来将值插入下表?
- visual-studio-code - Linux Mint 上的 VSCode,集成终端无法输入任何内容
- stack-overflow - 我们可以使用空手道工具自动化 Windows 服务吗?
- python - 如何将值从另一个数据帧映射到另一个数据帧的标头
- scala - 如何获取在 GROUP BY 子句中分组的元素的 Seq?
- reactjs - 在 react-native 中用 createStructuredSelector 替换 useSelector
- java - Eclipse:使用 Coverage 进行测试会抛出 java.lang.instrument.IllegalClassFormatException
- ios - Swift右栏按钮项目填充问题?