简体   繁体   English

从作为字典中值的熊猫系列中提取索引

[英]extracting the indices from pandas series that are values in the dictionary

I have a dictionary where keys are of string type and values are pandas series that have the 'index value' structure.我有一个字典,其中键是字符串类型,值是具有“索引值”结构的熊猫系列。 I want to extract pandas series indices and make them keys in another dictionary with values per each index.我想提取 Pandas 系列索引,并将它们放在另一个字典中,每个索引都有值。 Are there any ways I can transform one dictionary into another?有什么方法可以将一本字典转换成另一本字典? Thanks.谢谢。

This is the example of the dictionary I am working with:这是我正在使用的字典示例:

value = pd.Series([5,5,5])
key = ['one', 'two', 'three']
dic = {}

for i in key:
        dic[i] = value      
print(dic)

This should work.这应该有效。

df = pd.DataFrame(your_dic).T #transpose
new_dic = df.to_dict()

My apologies if I was not clear enough.如果我不够清楚,我深表歉意。 I will update the post.我会更新帖子。

I figured out another way to do so:我想出了另一种方法来做到这一点:

rec = pd.Series([])

for item in key:
    rec=rec.append(dic[item])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM