使用python写一段代码,获取指定路径excel的内容生产基础柱状图,其中A列为BUG单号,B列为BUG创建日期,F列为BUG分类,按照BUG分类生成每日新增的BUG量图表,其中BUG创建日期只精确到日,并将生成的图表重命名为“当前日期”保存到指定路径
时间: 2023-06-05 17:07:45 浏览: 93
好的,我可以为您提供一段python代码,用于获取指定路径excel的内容并生成基础柱状图。这是代码:
```
import pandas as pd
import matplotlib.pyplot as plt
import datetime
# 设置路径和文件名
path = '指定的路径和文件名.xlsx'
sheet_name = 'Sheet1'
# 读取excel表格
df = pd.read_excel(path, sheet_name=sheet_name)
# 将日期列转换为datetime格式并仅保留日期
df['日期'] = pd.to_datetime(df['日期'], format='%Y-%m-%d').dt.date
# 按照分类计算每日新增的BUG量
bug_count = df.groupby(['分类', '日期']).count().iloc[:, 0].reset_index()
# 绘制柱状图
for category in bug_count['分类'].unique():
data = bug_count[bug_count['分类'] == category].set_index('日期')
plt.bar(data.index, data.iloc[:, 0], label=category)
# 设置图表标题和标签
plt.title('BUG量')
plt.xlabel('日期')
plt.ylabel('数量')
plt.legend()
# 生成图表并保存
plt.savefig(datetime.date.today().strftime('%Y%m%d') + '.png')
plt.show()
```
请确保您已经安装了pandas和matplotlib库。如果您没有安装,请运行以下命令:
```
pip install pandas
pip install matplotlib
```
该代码将按照您指定的路径读取Excel文件,并计算每天的新增BUG量。然后,对于每个不同的BUG分类,将生成一个柱状图。最后,程序将使用当前日期作为文件名,并将图表保存到指定路径。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)