python boders数据读取

import pandas as pd
import numpy as np
Filename = r'F:\数据科学入门课件\territories.xlsx'
df = pd.DataFrame(pd.read_excel(Filename))
Filename = r'F:\数据科学入门课件\area_length_2.xlsx'
df2 = pd.DataFrame(pd.read_excel(Filename))


#读入第一列数据——LPoint
LPoint = df['left'].tolist()


#读入第二列数据——RPoint
RPoint = df['right'].tolist()

#读入边长
Len = df['length'].tolist()
Len = [float(x) for x in Len]

#生成边的信息
LP=zip(LPoint,RPoint)
LP_list = [x for x in LP]
LP_list = list(set(LP_list))

#生成节点信息
df_nodes = df2['country']
Nodes = list(df_nodes)

#读取国家边界长度
df_clength = df2['Clength']
CLength = list(df_clength)


#读取国家面积
df_area = df2['area']
Area = list(df_area)

import networkx as nx
borders = nx.Graph()
#for node in Nodes:
#    borders.add_node(node)
borders.add_nodes_from(Nodes)

#borders.nodes()    
#borders.number_of_nodes()

#for item in LP_list:
#    borders.add_edge(item[1],item[0])
borders.add_edges_from(LP_list)
        

#borders.edges()
#borders.number_of_edges()

#添加边属性,为相邻国家的距离
for item in LP_list:
    x = item[0]
    y = item[1]
    ind = LP_list.index(item)
    borders[x][y]['weight']= Len[ind]

#添加节点属性,每个国家的面积
for n in Nodes:
    ind_n = Nodes.index(n)
    borders.node[n]['area'] = Area[ind_n]
    borders.node[n]['L'] = CLength[ind_n]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值