将两个列表变成一个字典,对应着一个为key,一个为value

import pandas as pd
import numpy as np

aa = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
bb = [10, 21, 10, 21, 21, 10, 23, 23, 25, 25]
cc = [0, 1, 1, 2, 0, 0, 2, 2, 0, 0]
dd = [1, 2, 2, 4, 1, 6, 7, 8, 9, 10]
ee = [10, 21, 21, 21, 10, 10, 23, 23, 25, 25]
ff = [0, 1, 1, 2, 0, 0, 2, 2, 0, 0]
gg = [10, 21, 21, 21, 10, 10, 23, 23, 25, 25]

df_ = pd.DataFrame(
    {'id': aa, 'source': bb, 'target': cc, 'x_source': dd, 'x_target': ee, 'y_source': ff, 'y_target': gg})

df_['x_y_source'] = df_[['x_source', 'y_source']].apply(tuple, axis=1)
df_['x_y_target'] = df_[['x_target', 'y_target']].apply(tuple, axis=1)
print(df_)
s_t_dict = list(set(df_['x_y_source'].tolist() + df_['x_y_target'].tolist()))
print(s_t_dict)
aa_list = [i for i in range(1, len(s_t_dict) + 1)]
print(aa_list)
avail = {key: value for key, value in zip(s_t_dict, aa_list)}
print(avail)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值