Python 绘画excel分组柱状图(懒人学习)

这篇博客介绍了如何使用Python的pandas和matplotlib库绘制Excel数据的分组柱状图。首先展示了Excel案例,然后提供了一段完整的Python代码,包括数据读取、排序、画图等步骤,并详细解释了每部分代码的功能。最后展示了生成的图表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.excel案例如截图:

很简单大家自己照着做一个就可以了。
在这里插入图片描述

2.完整代码如下:

import pandas as pd
import matplotlib.pyplot as plt

students = pd.read_excel(‘H:/Python自动化办公–Pandas玩转Excel源代码(7-30)/010/Students.xlsx’)
students.sort_values(by=‘2017’, inplace=True, ascending=False)
print(students)
students.plot.bar(‘Field’, [‘2016’, ‘2017’], color=[‘orange’, ‘Red’])
plt.title(‘International Students by Field’, fontsize=16)
plt.xlabel(‘Field’, fontweight=‘bold’)
plt.ylabel(‘Number’, fontweight=‘bold’)

plt.tight_layout()

ax = plt.gca()
ax.set_xticklabels(students[‘Field’], rotation=40, ha=‘right’)
plt.gcf().subplots_adjust(left=0.2, bottom=0.42)
plt.show()


3、代码解释

3.1引入库

代码如下(示例):

import pandas as pd
import matplotlib.pyplot as plt

引入pandas,matplotlib库,没有的话自己安装一个。

3.2读入数据

代码如下(示例):

students = pd.read_excel('H
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_42210634

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值