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!
Answers:
Simply use
pd.DataFrame(Corpus_dict)
It will give the dataframe which you wanted.
Found Similar Question here
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!
Simply use
pd.DataFrame(Corpus_dict)
It will give the dataframe which you wanted.
Found Similar Question here