#读取“农村居民人均可支配收入来源2016.xlsx”数据表,其中数据来源于2016年《中国统计年鉴》,
#首先,对指标数据进行均值方差标准化处理
#其次,其次对标准化处理后的指标数据作主成分分析,要求提前累计贡献率在95%以上
#再次,基于提取的主成分计算综合得分,综合得分=提取的各主成分与对应贡献率之和
#最后,基于综合得分获得各地区的排名,得分按从高到低排序,用一个序列Rs来表示,其中index为地区名称,值为综合得分
def return_values():
import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
data=pd.read_excel('农村居民人均可支配收入来源2016.xlsx')
x=data.iloc[:,1:]
scaler=StandardScaler()
scaler.fit(x)
x=scaler.transform(x)
pca=PCA(n_components=0.95)
pca.fit(x)
y=pca.transform(x)
gxl=pca.explained_variance_ratio_
F=gxl[0]*y[:,0]+gxl[1]*y[:,1]+gxl[2]*y[:,2]
dq=list(data['地区'].values)
Rs=pd.Series(F,index=dq)
Rs=Rs.sort_values(ascending=False)
return Rs