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