一、CSV文件来源:
http://data.stats.gov.cn/easyquery.htm?cn=C01 国家数据网
如果还没有数据让你分析的同学可以去这里找一找,啥都有
二、代码:
import pandas as pd from pandas import Series,DataFrame import matplotlib.pyplot as plt import seaborn as sea plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 filename = 'D:\360极速浏览器下载\年度数据.csv' f = open(filename) df = pd.read_csv(f,header=2).head(28) df = DataFrame(df) df.drop(columns='指标',inplace=True) df.fillna(0,inplace=True) s = df[df.keys()].sum() s = Series(s).sort_index(ascending=True) x = s.keys() y = s.values color = ['red','blue','pink','green','DarkGreen','yellow','Tomato','LightPink','MediumTurquoise'] plt.pie(y,labels=x,colors=color,autopct='%.1f%%') plt.show()
效果: