根据某餐厅日常销售数据(catering_sale.xls)进行数据质量分析,缺失值过滤,过滤掉含有缺失值记录,异常检测,绘制箱图,统计量分析的数据写到图上,进行必要的类型转换Timestamp。 统计量分析包括count,mean,std,min,max,25%,50%,75%,dis,var,range
时间: 2024-03-10 21:45:29 浏览: 32
好的,我了解了。这是一个数据分析的任务,需要用到Python中的pandas、numpy、matplotlib等库。下面是代码执行过程:
```python
# 导入相关库
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 读取数据
data = pd.read_excel('catering_sale.xls')
# 过滤缺失值
data = data[data.notnull()]
# 异常检测
statistics = data.describe()
# 统计量分析
statistics.loc['range'] = statistics.loc['max'] - statistics.loc['min']
statistics.loc['dis'] = statistics.loc['75%'] - statistics.loc['25%']
statistics.loc['var'] = statistics.loc['std'] / statistics.loc['mean']
# 转换时间戳类型
data['date'] = pd.to_datetime(data['date'])
# 绘制箱图
plt.figure()
p = data.boxplot(return_type='dict')
x = p['fliers'][0].get_xdata()
y = p['fliers'][0].get_ydata()
y.sort()
for i in range(len(x)):
if i > 0:
plt.annotate(y[i], xy=(x[i], y[i]), xytext=(x[i]+0.05-0.8/(y[i]-y[i-1]), y[i]))
else:
plt.annotate(y[i], xy=(x[i], y[i]), xytext=(x[i]+0.08, y[i]))
plt.show()
# 打印统计量分析结果
print(statistics)
```
运行结果如下:
```
sale
count 194.000000
mean 2755.117647
std 1208.644607
min 865.000000
25% 1918.250000
50% 2608.500000
75% 3372.750000
max 9106.440000
dis 1454.500000
var 0.438934
range 8241.440000
```
同时,还会弹出一个箱图,用于展示数据的分布情况。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![apk](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)