一、导入相关包
#coding:utf-8
#导入warnings包,利用过滤器来实现忽略警告语句。
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np
%matplotlib inline
二、总体情况一览
inputfile = '../data/original_data.xls' # 输入的数据文件
data = pd.read_excel(inputfile) # 读取数据
print(data.info())
print(data.describe())
print(data.count())
data.head()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 18840 entries, 0 to 18839
Data columns (total 12 columns):
热水器编号 18840 non-null object
发生时间 18840 non-null int64
开关机状态 18840 non-null object
加热中 18840 non-null object
保温中 18840 non-null object
有无水流 18840 non-null object
实际温度 18840 non-null object
热水量 18840 non-null object
水流量 18840 non-null int64
节能模式 18840 non-null object
加热剩余时间 18840 non-null object
当前设置温度 18840 non-null object
dtypes: int64(2), object(10)
memory usage: 1.7+ MB
None
发生时间 水流量
count 1.884000e+04 18840.000000
mean 2.014106e+13 12.870594
std 4.021530e+07 17.122814
min 2.014102e+13 0.000000
25% 2.014102e+13 0.000000
50% 2.014103e+13 0.000000
75% 2.014111e+13 26.000000
max 2.014111e+13 77.000000
热水器编号 18840
发生时间 18840
开关机状态 18840
加热中 18840
保温中 18840
有无水流 18840
实际温度 18840
热水量 18840
水流量 18840
节能模式 18840
加热剩余时间 18840
当前设置温度 18840
dtype: int64
热水器编号 | 发生时间 | 开关机状态 | 加热中 | 保温中 | 有无水流 | 实际温度 | 热水量 | 水流量 | 节能模式 | 加热剩余时间 | 当前设置温度 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | R_00001 | 20141019063917 | 关 | 关 | 关 | 无 | 30°C | 0% | 0 | 关 | 0分钟 | 50°C |
1 | R_00001 | 20141019070154 | 关 | 关 | 关 | 无 | 30°C | 0% | 0 | 关 | 0分钟 | 50°C |
2 | R_00001 | 20141019070156 | 关 | 关 | 关 | 无 | 30°C | 0% | 8 | 关 | 0分钟 | 50°C |
3 | R_00001 | 20141019071230 | 关 | 关 | 关 | 无 | 30°C | 0% | 0 | 关 | 0分钟 | 50°C |
4 | R_00001 | 20141019071236 | 关 | 关 | 关 | 无 | 29°C | 0% | 0 | 关 | 0分钟 | 50°C |
三、数据分析
水流状态
# 绘制条形图
fig = plt.figure(figsize=(6, 5)) # 设置画布大小
sns.set(style="darkgrid")
sns.set_context("notebook", font_scale=1.2, rc={"lines.linewidth": 2.5})
plt.rcParams['font.sans-serif'] = 'SimHei' # 设置中文显示
plt.rcParams['axes.unicode_minus'] = False
sns.catplot(kind="count",
data=data,
x="有无水流",
aspect=1,
height=5,
palette='tab20')
plt.xlabel('水流状态')
plt.ylabel('记录数')
plt.title('不同水流状态记录数')
水流量分布
# 绘制水流量分布箱型图
fig = plt.figure(figsize=(5, 8))
sns.catplot(
kind="box",
data=data,
y='水流量', # 设置x轴标题
aspect=1,
height=5,
palette='tab20')
plt.title('水流量分布箱线图')
#显示y坐标轴的底线
#plt.grid(axis='y')
由分箱图可以看出,用户一半以上的时间都没在用水,刚好和条形图对应