import pandas as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import rcParams # 中文处理模块
rcParams['font.family'] = 'simhei' # 不然文字乱码
df = pd.read_excel('./data/2-1.xlsx')
df2 = df.value_counts().rename_axis('评价等级').reset_index(name='count')
# 对于Series,rename_axis可以给index改名字,但不支持给value列改名字。
# 用到reset_index给value列重命名。
colorlist=["darkorange", "gold", "lawngreen", "lightseagreen",'darkblue']
df2.plot.bar(x='评价等级', y='count', color=colorlist)
# print(df2)
plt.xticks(rotation=360)
# 旋转X轴标签,是标签横向展示
plt.show()
''' df2结果
评价等级 count
0 C 32
1 B 21
2 D 18
3 E 15
4 A 14'''
结果展示