跑回归的时候发现网上的资源都要钱了,所以手搓了一份。
PS:不含港澳台。(主要是我跑数据的时候没用到)
预览:
省会地理距离矩阵
省会地理距离矩阵(取倒数)
省会地理距离矩阵(取平方倒数)
链接(蓝奏云):https://wwf.lanzout.com/idNFg0ezcsrc
密码:duht
代码虽然没什么技术含量但姑且贴一下:
import pandas as pd
import numpy as np
import math
loc = {'山东':[117.000923, 36.675807],
'河北':[115.48333,38.03333],
'吉林':[125.35000,43.88333],
'黑龙江':[127.63333,47.75000],
'辽宁':[123.38333,41.80000],
'内蒙古':[111.670801, 41.818311],
'新疆':[87.68333,43.76667],
'甘肃':[103.73333,36.03333],
'宁夏':[106.26667,37.46667],
'山西':[112.53333,37.86667],
'陕西':[108.95000,34.26667],
'河南':[113.65000,34.76667],
'安徽':[117.283042, 31.86119],
'江苏':[119.78333,32.05000],
'浙江':[120.20000,30.26667],
'福建':[118.30000,26.08333],
'广东':[113.23333,23.16667],
'江西':[115.90000,28.68333],
'海南':[110.35000,20.01667],
'广西':[108.320004, 22.82402],
'贵州':[106.71667,26.56667],
'湖南':[113.00000,28.21667],
'湖北':[114.298572, 30.584355],
'四川':[104.06667,30.66667],
'云南':[102.73333,25.05000],
'西藏':[91.00000,30.60000],
'青海':[96.75000,36.56667],
'天津':[117.20000,39.13333],
'上海':[121.55333,31.20000],
'重庆':[106.45000, 29.56667],
'北京': [116.41667,39.91667],
'台湾': [121.30, 25.03],
'香港': [114.10000,22.20000],
'澳门': [113.50000,22.20000],
} #拿到的坐标原始数据就长这样,换成读表格也差不多
df = pd.read_excel("金融指数.xlsx",sheet_name="2020") #按需要顺序排列省份名称
lis = df.iloc[0:,0:1].values
mat1 = np.zeros((31,31)) #存放地理距离
mat2 = np.zeros((31,31)) #存放地理距离倒数
for i in range(31):
for j in range(31):
if i == j:
continue
else:
ja = loc[lis[i][0]][0] / 180 * math.pi
jb = loc[lis[j][0]][0] / 180 * math.pi
wa = loc[lis[i][0]][1] / 180 * math.pi
wb = loc[lis[j][0]][1] / 180 * math.pi
mat1[i][j] = 6371 * math.acos(math.cos(wa)*math.cos(wb)*math.cos(jb-ja)+math.sin(wa)*math.sin(wb))
mat2[i][j] = 1 / mat1[i][j]
mat3 = pd.DataFrame(mat1)
mat4 = pd.DataFrame(mat2)
writer = pd.ExcelWriter("矩阵.xlsx")
tar3.to_excel(writer, 'geom', float_format='%.6f')
tar4.to_excel(writer, 'igeom', float_format='%.6f')
writer.save()
writer.close()