Data frame:
pair = collections.defaultdict(collections.Counter)
e.g.
pair = {'doc1': {'word1':4, 'word2':3},
'doc2': {'word1':2, 'word3':4},
'doc3': {'word2':2, 'word4':1},
...}
I want to keep the data frame but alter the type of this part {'word1':4, 'word2':3}
{'word1':2, 'word3':4}``...
It is now a Counter
and I need a dict
.
I tried this to get the data from pair
, but I do not know how to create a dict
for each doc:
new_pair = collections.defaultdict(collections.Counter)
for doc, tab in testing.form.items():
for word, freq in tab.items():
new_pair[doc][word] = freq
I do not want to change the output. I just need that in each doc, the data type is dict
, not Counter
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…