【发布时间】:2019-01-31 10:54:04
【问题描述】:
我想在 pandas 中调用计数器值。
目前的努力:
from __future__ import unicode_literals
import spacy,en_core_web_sm
from collections import Counter
import pandas as pd
nlp = en_core_web_sm.load()
c = Counter(([token.pos_ for token in nlp('The cat sat on the mat.')]))
sbase = sum(c.values())
for el, cnt in c.items():
el, '{0:2.2f}%'.format((100.0* cnt)/sbase)
df = pd.DataFrame.from_dict(c, orient='index').reset_index()
print df
电流输出:
index 0
0 NOUN 2
1 VERB 1
2 DET 2
3 ADP 1
4 PUNCT 1
预期输出:
下面的内部数据框:
(u'NOUN', u'28.57%')
(u'VERB', u'14.29%')
(u'DET', u'28.57%')
(u'ADP', u'14.29%')
(u'PUNCT', u'14.29%')
我想在数据框里面怎么调用el和cnt?
这是一个后续问题,我想列出列出的 POS 分布百分比。
Percentage Count Verb, Noun using Spacy?
我知道我需要将组 el 和 cnt 放在下面的 c 位置:
df = pd.DataFrame.from_dict(c, orient='index').reset_index()
【问题讨论】:
标签: pandas