python - Python 改变我的绘图数据点?[直方图]
问题描述
尝试从 Excel 工作表中提取数据,应用方程(在本例中median()
),并从该数据创建直方图。
这是我的代码:
import pandas as pd
import matplotlib.pyplot as plt
pd.set_option('display.max_columns', 100000)
absent = pd.read_excel('Absenteeism_at_work.xls')
col = ['Distance from Residence to Work', 'Transportation expense', 'Month of absence', 'Social smoker',
'Social drinker', 'Education']
# print(absent.loc[:741, col])
plt.title('The Mean')
plt.xlabel('Attribute of Absence')
plt.ylabel('Value')
# x = ['Distance', 'Trans Exp.', 'Month', 'Smoker', 'Drinker', 'Edu.']
x = absent.loc[:741, col].median()
x.plot(kind="bar", figsize=(5, 5))
print(x)
plt.hist(x)
# print(hist)
plt.show() # shows histogram in side-window
这是终端输出:
Distance from Residence to Work 26.0
Transportation expense 225.0
Month of absence 6.0
Social smoker 0.0
Social drinker 1.0
Education 1.0
dtype: float64
最重要的是,不正确的直方图:
“社交吸烟者”不应该显示为 0 吗?另外,“从住所到工作的距离”右侧的那条额外的栏是什么?这合适吗?谢谢!
解决方案
推荐阅读
- c# - 如何使用 Rg.Plugins.Popup 将 XAML 和模板组合成一个 C# 模板?
- c++ - 进程以 -1073741571 状态终止,具有百万点的最近对算法
- python - 为什么我应该使用散列向量器进行文本聚类?
- node.js - 无法使用 Node.js 从嵌套目录中获取文件内容
- macos - 在 macOS 上通过终端输入 Sublime Text 许可证密钥
- spring - 方面未运行 | 弹簧启动
- javascript - 在 IndexedDB 成功处理程序之外更新变量
- java - WebClient.RequestHeadersSpec 是原始类型
- python - 只删除熊猫中完全空的行
- spyder - 如何在不关闭的情况下保存 Spyder IDE 状态?