How to convert Counter object to dict?

前端 未结 4 1790
独厮守ぢ
独厮守ぢ 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:57

    new_pair = {} # simple dict at the top level
    for doc, tab in testing.form.items():
        for word, freq in tab.items():
            # top-level values is word counters
            new_pair[doc].setdefault(word, Counter()) += freq
    

提交回复
热议问题