How to convert Counter object to dict?

前端 未结 4 1780
独厮守ぢ
独厮守ぢ 2020-12-29 20:08

Data frame:

pair = collections.defaultdict(collections.Counter)

e.g.

pair = {\'doc1\':  {\'word1\':4, \'word2\':3}, 
               


        
4条回答
  •  不思量自难忘°
    2020-12-29 20:45

    The Counter is also a dict. But depend on you need, maybe the follow code is you want.

    new_pair ={}
    for doc, tab in pari.items():
        new_pair[doc] = {}
        for word, freq in tab.items():
            new_pair[doc][word] = freq
    

    the new_pair dict is you want. Good Luck!

提交回复
热议问题