【发布时间】:2022-06-19 02:23:11
【问题描述】:
我正在尝试将我保存在列表“root”中的值与字典中的键匹配,这样我就可以获得这些值。但我不知道该怎么做。 :/也许有人对我有一些启发。非常感谢!
因此我创建了一本字典。
from turtle import clear
import pandas as pd
df=pd.read_excel(r'path').fillna("@Null$tring").sort_values(by=['VP'])
SP = df['SP'].tolist()
VP = df['VP'].tolist()
root = []
#sSP = set(SP)
#sVP = set(VP)
root = [i for i in SP if i not in VP]
#index =root.index
print(root)
#print(index(root))
d = dict (zip(SP,VP))
for key in d.keys():
if key == root[0]:
print(key)
【问题讨论】:
-
查看
difference方法 -
所以您需要从字典
d创建一个值列表,其中键是列表root的项目?如果是这样,[d[key] for key in root] 将完成这项工作。 -
嗨,我更新了我的问题的解释。我在列表中有值,我需要知道这些值是否作为字典中的键,以便我可以获得各自的值
标签: python