Convert Dictionary to Pandas DataFrame

Question:

I have a Python dictionary of dictionaries that models the TF-IDF weights of words in a set of documents. Like that:

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 }}

Where xxx is the TF-IDF value for each of n words. I’d like to convert it to the folowing Pandas Data Frame:

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!

Asked By: yuridamata

||

Answers:

Simply use

pd.DataFrame(Corpus_dict)

It will give the dataframe which you wanted.

Found Similar Question here

Answered By: Geetha Ponnusamy

The answer of your question is should be like in the below picture.

enter image description here

Answered By: Batuhan B
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.