截至2022年近10年中国人口数据
2026/6/6 5:13:11 网站建设 项目流程


#转置数据框,按索引(年份)升序排列数据框,以便后续计算环比指标
df_total_T=df_total.T
df_total_T=df_total_T.sort_index()
df_total_T


#计算各个指标的年环比指标
cols=df_total_T.columns.to_list()
for col in cols:
col_str=col+"_pct"
df_total_T[col_str]=df_total_T[col].pct_change(periods=1)
df_total_T.head(2)


#年末总人口规模和环比趋势分析。
fig=plt.figure(figsize=(12,6))#设置画布


ax1=fig.add_subplot(2,1,1)
ax1.plot(df_total_T['年末总人口(万人)'])
ax1.axhline(y=140000,color='red')#14亿红线
ax1.set_title('年末总人口(万人)趋势')

ax2=fig.add_subplot(2,1,2)
ax2.plot(df_total_T['年末总人口(万人)_pct'])
ax2.axhline(y=0,color='red')#正负值界限
ax2.set_title('年末总人口(万人)_pct趋势')

plt.tight_layout()
plt.show()


plt.figure(figsize=(12,4))
plt.plot(df_total_T['城镇人口(万人)']/df_total_T['年末总人口(万人)'],marker='+')
plt.axhline(y=0.5,color='red')
plt.title('城镇人口占比')
plt.show()


plt.figure(figsize=(12,4))
plt.plot(df_total_T['男性人口(万人)']/df_total_T['年末总人口(万人)'])
plt.axhline(y=0.5,color='red')
plt.title('男性人口占比')
plt.show()


plt.figure(figsize=(12,4))#画布设置

plt.plot(df_total_T['城镇人口(万人)_pct'],label='城镇环比')
plt.plot(df_total_T['乡村人口(万人)_pct'],label='乡村环比')
plt.plot(df_total_T['年末总人口(万人)_pct'],label="总人口环比")
plt.axhline(y=0,color='red')#正负值红线

plt.legend()
plt.title('城镇化环比速度')
plt.show()


df_ngr=pd.read_csv("/home/mw/input/population5417/出生率死亡率自然增长率.csv",encoding='gbk',index_col=0)#数据框加载
df_ngr_T=df_ngr.T#数据框转置
df_ngr_T=df_ngr_T.sort_index()#按年升序排列
df_ngr_T=df_ngr_T.dropna(how="all")#删除全是空值的行
df_ngr_T


plt.figure(figsize=(12,6))#设置画布

plt.plot(df_ngr_T)
plt.axhline(y=0,color='red')#正负值红线

plt.legend(['人口出生率(‰)','人口死亡率(‰)','人口自然增长率(‰)','0线'])#图例设置
plt.title("出生率死亡率自然增长率趋势")#标题设置
plt.show()


df_age=pd.read_csv("/home/mw/input/population5417/人口年龄分布.csv",encoding='gbk',index_col=0)#加载数据
df_age_T=df_age.T#数据框转置
df_age_T=df_age_T.sort_index()#按年升序排列
df_age_T=df_age_T.dropna(how="all")#去全空值行
df_age_T.head(2)


l_male=df_age_male_T.columns.to_list()
print("low:",l_male.index('20-24岁男性人口数(人口抽样调查)(人)'))#20-24岁男性人口数(人口抽样调查)(人)在数据框列中的索引位置数值
print("high:",l_male.index('50-54岁男性人口数(人口抽样调查)(人)'))#50-54岁男性人口数(人口抽样调查)(人)在数据框列中的索引位置数值
df_age_male_T['男性适婚适孕']=df_age_male_T.iloc[:,5:12].sum(axis=1)#设置字段男性适婚适孕并赋值


df_age_female=pd.read_csv("/home/mw/input/population5417/女性年龄分布.csv",encoding='gbk',index_col=0)
df_age_female_T=df_age_female.T
df_age_female_T=df_age_female_T.sort_index()
df_age_female_T=df_age_female_T.dropna(how="all")
df_age_female_T.head(2)


df_edu_T.columns


设置6岁及6岁以上未上过学人口占比(人口抽样调查)字段并赋值
df_edu_T['6岁及6岁以上未上过学人口占比(人口抽样调查)']=df_edu_T['6岁及6岁以上未上过学人口数(人口抽样调查)(人)']/df_edu_T['6岁及6岁以上人口数(人口抽样调查)(人)']


plt.figure(figsize=(12,6))

plt.plot(df_edu_T['6岁及6岁以上未上过学人口占比(人口抽样调查)'],label="未上过学人口占比")
#plt.plot(df_edu_T['6岁及6岁以上未上过学女性人口占比(人口抽样调查)'],label="未上过学女性人口占比")

plt.legend()
plt.title("6岁及6岁以上未上过学人口占比(人口抽样调查)")
plt.show()

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询