繁体   English   中英

Python 改变了我的绘图数据点? [直方图]

[英]Python altering my plot data points? [histogram]

尝试从 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

最重要的是,不正确的直方图:

基于上述数据的中值直方图(忽略“平均值”)

'Social Smoker' 不应该显示为 0 吗? 另外,“从住宅到工作的距离”右侧的额外栏是什么? 这合适吗? 谢谢!

您的图表x.plot(kind="bar", figsize=(5, 5))plt.hist(x)合并在一起。

x.plot(kind="bar", figsize=(5, 5)):

在此处输入图片说明

plt.hist(x):

在此处输入图片说明

综合:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM