# -*- coding: utf-8 -*- import pandas as pd # -*- coding: utf-8 -*- import seaborn as sns import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 #sns.set_style(style="whitegrid") #背景的样式,一定要注释此行 #文件路径 file_path='data.xlsx' #读取sheet的名字 sheetName='train1' df=pd.read_excel(file_path,sheet_name=sheetName,encoding='utf-8') #print(df.index.values) #print(df.shape[0])#总行数 #处理 beimei=0 ya=0 ou=0 nanmei=0 dayang=0 fei=0 for i in range(1,df.shape[0]): zhou=df.iloc[i]['zhou'] year=df.iloc[i]['year'] if zhou=="北美洲" and str(year)=="1990": beimei+=df.iloc[i]['value'] elif zhou=="亚洲" and str(year)=="1990": ya+=df.iloc[i]['value'] elif zhou=="欧洲" and str(year)=="1990": ou+=df.iloc[i]['value'] elif zhou=="南美洲" and str(year)=="1990": nanmei+=df.iloc[i]['value'] elif zhou=="大洋洲" and str(year)=="1990": dayang+=df.iloc[i]['value'] elif zhou=="非洲" and str(year)=="1990": fei+=df.iloc[i]['value'] names=["北美","亚洲","欧洲","南美","大洋洲","非洲"] values=[beimei,ya,ou,nanmei,dayang,fei] # sns.set_context(context="poster",font_scale=0.8) # sub_df=df.groupby("zhou").mean() # sns.pointplot(sub_df.index,sub_df["year"]) # sns.pointplot(x="zhou",y="value",data=df) # plt.show() plt.title("1990年各洲森林面积") plt.xlabel("各大洲") plt.ylabel("面积(m3)") plt.plot(names,values) plt.show()
python读excel数据可视化,重新处理数据
阅读:3647 输入:2020-12-14 11:23:09