Python从一系列FreqDis中获取FreqDist键的最新出现

2024-09-30 20:26:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是生成一个单词字典,在过去的3年里,有不同的FreqDist键,但最近出现的时间。在

我已经生成了一个字典,其中的键表示日期,以及对应于该月提取的FreqDist的值。在

{'20151': FreqDist({'physiotherapy': 11, 'claimant': 5, 'rehabilitation': 4, 'agent': 3, 'assessment': 3, 'client': 2, 'via': 1, 'jigsaw': 1, 'ticc': 1, 'accupuncture': 1, ...})}
{'20152': FreqDist({'physiotherapy': 12, 'rehabilitation': 7, 'assessment': 4, 'treatment': 4, 'claimant': 3, 'ltd': 3, 'appointment': 2, 'provider': 2, 'medical': 2, 'service': 2, ...})}

...

{'20184': FreqDist({'physiotherapy': 10, 'rehabilitation': 9, 'client': 8, 'claimant': 6, 'assessment': 5, 'ticc': 5, 'agent': 3, 'treatment': 3, 'symptom': 3, 'ltd': 3, ...})}
{'20185': FreqDist({'rehabilitation': 21, 'physiotherapy': 15, 'client': 9, 'assessment': 7, 'ticc': 6, 'agent': 6, 'detail': 5, 'ltd': 4, 'arrangement': 3, 'simply': 3, ...})}.

然后我就可以通过

^{pr2}$

不知道我该如何报告最近发生的那些不同的频率分配键给这个月??在


Tags: client目标字典时间单词viaagentassessment
1条回答
网友
1楼 · 发布于 2024-09-30 20:26:37

使用熊猫:

import pandas as pd
from collections import defaultdict

ser = pd.Series([{'physiotherapy':10,'rehabilitation':9},
                 {'rehabilitation':21,'physiotherapy':15},
                 {'physiotherapy':12}])

count = defaultdict(int)

for d in ser:
    for key in d:
        count[key] += 1

print(count)

或者:

^{pr2}$

相关问题 更多 >