Excel的简单排序并且可视化
import pandas as pd
import matplotlib.pyplot as plt
tata2=pd.read_excel("Tata.xlsx")#打开Excel
tata2.sort_values(by="age",inplace=True,ascending=False)#对age里的数据排序
plt.bar(tata2.name,tata2.age,color="orange")#柱状图显示name和age
plt.title("jjh",fontsize=18)
plt.xlabel("tata1")
plt.ylabel("values")#两个坐标轴
plt.xticks(tata2.name,rotation="90")#字体旋转90度
plt.tight_layout()#紧凑型
plt.show()
显示中文:
import pandas as pd
import matplotlib.pyplot as plt
tata2=pd.read_excel("Tata.xlsx")#打开Excel
tata2.sort_values(by="age",inplace=True,ascending=False)#对age里的数据排序
plt.bar(tata2.name,tata2.age,color="orange")#柱状图显示name和age
#plt.title("jjh",fontsize=18)
#plt.xlabel("tata1")
#plt.ylabel("values")#两个坐标轴
#添加显示字体
from matplotlib.font_manager import FontProperties
#sinsun,ttc 简体字
font=FontProperties(fname=r"C:\WINDOWS\Fonts\SimSun.ttc",size=18)
plt.title("年龄",fontproperties=font)
plt.xlabel("年龄",fontproperties=font,fontsize=18)
plt.ylabel("数量",fontproperties=font,fontsize=18)#两个坐标轴
plt.xticks(tata2.name,rotation="90")#字体旋转90度
plt.tight_layout()#紧凑型
plt.show()