python獲取表格每天大於4H數量與比例生成推移圖
时间: 2023-08-11 17:44:34 浏览: 41
好的,我可以为您解答这个问题,并帮您生成推移图。首先,您需要使用Python中的pandas和matplotlib库来进行数据处理和图形绘制。具体步骤如下:
1. 导入必要的库和数据
```python
import pandas as pd
import matplotlib.pyplot as plt
# 读取数据
df = pd.read_excel('data.xlsx')
```
2. 对数据进行处理
```python
# 计算每天大于4小时的数量
df['greater_than_4h'] = df['duration'] > 4
df['greater_than_4h_count'] = df.groupby('date')['greater_than_4h'].sum()
# 计算比例
df['greater_than_4h_ratio'] = df['greater_than_4h_count'] / len(df)
```
3. 绘制推移图
```python
# 绘制推移图
plt.plot(df['date'], df['greater_than_4h_count'], label='Count')
plt.plot(df['date'], df['greater_than_4h_ratio'], label='Ratio')
plt.legend()
plt.show()
```
这样就可以生成每天大于4小时数量和比例的推移图了。需要注意的是,您需要将数据放入一个名为"data.xlsx"的Excel文件中,并且数据格式需要符合要求。