简体   繁体   English

将字典转换为Pandas DataFrame

[英]Convert Dictionary to Pandas DataFrame

I have a Python dictionary of dictionaries that models the TF-IDF weights of words in a set of documents. 我有一本字典的Python字典,该字典对一组文档中单词的TF-IDF权重进行建模。 Like that: 像那样:

Corpus_dict = {"Doc1.txt": {'word1': XXXX , 'word2': XXXX , ... , wordn: xxx } "Doc2.txt": {'word1': XXXX , 'word2': XXXX , ... , wordn: xxx } Corpus_dict = {“ Doc1.txt”:{'word1':XXXX,'word2':XXXX,...,wordn:xxx}“ Doc2.txt”:{'word1':XXXX,'word2':XXXX,。 ..,wordn:xxx}
... "Docm.txt": {'word1': XXXX , 'word2': XXXX , ... , wordn: xxx }} ...“ Docm.txt”:{'word1':XXXX,'word2':XXXX,...,wordn:xxx}}

Where xxx is the TF-IDF value for each of n words. 其中xxx是n个字中每个字的TF-IDF值。 I'd like to convert it to the folowing Pandas Data Frame: 我想将其转换为以下Pandas数据框:

keys     Doc1      Doc2   ...   Docn

word1     xxx        xxx         xxx
word2     xxx        xxx         xxx
                      ...
word      nxxx       xxx         xxx

Can someone give me some help? 有人可以给我些帮助吗?

Sorry for bad english and thanks! 对不起,英语不好,谢谢!

Simply use 只需使用

pd.DataFrame(Corpus_dict)

It will give the dataframe which you wanted. 它将提供您想要的数据框。

Found Similar Question here 在这里找到类似的问题

The answer of your question is should be like in the below picture. 您的问题的答案应如下图所示。

在此处输入图片说明

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

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