看看这个。
data = {
"messages":
[
{"timestamp": "123456789", "timestampIso": "2019-06-26 09:51:00", "agentId": "2001-100001", "skillId": "2001-20000", "agentText": "That customer was great"},
{"timestamp": "123456789", "timestampIso": "2019-06-26 09:55:00", "agentId": "2001-100001", "skillId": "2001-20001", "agentText": "That customer was stupid\nI hope they don't phone back"},
{"timestamp": "123456789", "timestampIso": "2019-06-26 09:57:00", "agentId": "2001-100001", "skillId": "2001-20002", "agentText": "Line number 3"},
{"timestamp": "123456789", "timestampIso": "2019-06-26 09:59:00", "agentId": "2001-100001", "skillId": "2001-20003", "agentText": ""}
]
}
var = []
for row in data['messages']:
new_row = row['agentText'].split()
if new_row:
var.append(new_row)
temp = dict()
for e in var:
for j in e:
if j in temp:
temp[j] = temp[j] + 1
else:
temp[j] = 1
for key, value in temp.items():
print(f'{key}: {value}')