美文网首页
python和pandas处理excel(8)

python和pandas处理excel(8)

作者: OURPIECE | 来源:发表于2020-09-02 11:50 被阅读0次

柱状图

如下表

ID age score
1 16 80
2 15 96
3 18 88
4 16 75
5 23 90
6 12 65

场景1

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel("D:/python_test/shaixuan.xls")
print(df)
df = df.sort_values(by='score')
df.plot.bar(x='age',y='score')
plt.show()
无标题.png

场景2

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel("D:/python_test/shaixuan.xls")
print(df)
df = df.sort_values(by='score')
#df.plot.bar(x='age',y='score',color='orange',title='student score')
#定义x,y轴
plt.bar(df.age, df.score,color='orange')
#定义x轴名字角度
plt.xticks(df.age,rotation='60')
#定义x,y轴名称
plt.xlabel('age')
plt.ylabel('score')
plt.title('student score')
plt.tight_layout()
plt.show()
plt.show()
Figure_1.png

相关文章

网友评论

      本文标题:python和pandas处理excel(8)

      本文链接:https://www.haomeiwen.com/subject/tmqvdktx.html