我正在尝试分析一个包含来自Twitter API数据的JSON文件。我想找出主题标签或特定单词在我的数据集中出现的次数。我可以使用以下方法获取最常见的推文列表:
print(df.groupby('text').count().sort(desc('count')).show())
所以我知道,例如,利物浦在数据中绝对是一个词。
我只是想找出"利物浦"这个词在我的数据集中出现多少次,这可能吗?谢谢
我使用Spark版本1.6.0。
列命名为
['_corrupt_record', 'contributors', 'coordinates', 'created_at', 'delete',
'entities', 'favorite_count', 'favorited', 'filter_level', 'geo', 'id',
'id_str', 'in_reply_to_screen_name', 'in_reply_to_status_id',
'in_reply_to_status_id_str', 'in_reply_to_user_id', 'in_reply_to_user_id_str',
'lang', 'place', 'possibly_sensitive', 'retweet_count', 'retweeted',
'retweeted_status', 'scopes', 'source', 'text', 'truncated', 'user',
'withheld_in_countries']
不确定这是否适用于 1.6,我使用 2.1,但我会做类似的事情:
from pyspark.sql.functions import col
df.where(col('text').like("%Liverpool%")).count()