【发布时间】:2019-05-02 13:58:26
【问题描述】:
我正在尝试在标记化 Dataframe 的每一行中找到最常用的单词,如下所示:
print(df.tokenized_sents)
['apple', 'inc.', 'aapl', 'reported', 'fourth', 'consecutive', 'quarter', 'record', 'revenue', 'profit', 'combination', 'higher', 'iphone', 'prices', 'strong', 'app-store', 'sales', 'propelled', 'technology', 'giant', 'best', 'year', 'ever', 'revenue', 'three', 'months', 'ended', 'sept.']
['brussels', 'apple', 'inc.', 'aapl', '-.', 'chief', 'executive', 'tim', 'cook', 'issued', 'tech', 'giants', 'strongest', 'call', 'yet', 'u.s.-wide', 'data-protection', 'regulation', 'saying', 'individuals', 'personal', 'information', 'been', 'weaponized', 'mr.', 'cooks', 'call', 'came', 'sharply', 'worded', 'speech', 'before', 'p…']
...
wrds = []
for i in range(0, len(df) ):
wrds.append( Counter(df["tokenized_sents"][i]).most_common(5) )
但它会报告一个列表:
print(wrds)
[('revenue', 2), ('apple', 1), ('inc.', 1), ('aapl', 1), ('reported', 1)]
...
我想创建以下数据框;
print(final_df)
KeyWords
revenue, apple, inc., aapl, reported
...
注意最终数据框的行不是列表,而是单个文本值,例如收入,苹果公司,苹果公司,报告,不,[收入,苹果公司,苹果公司,报告]
【问题讨论】:
-
你能给我们输入数据框吗?
-
是开头打印的列(df.tokenized_sents),其他列与此无关;