]> code.communitydata.science - cdsc_reddit.git/blob - tfidf_authors.py
Add code for running tf-idf at the weekly level.
[cdsc_reddit.git] / tfidf_authors.py
1 from pyspark.sql import SparkSession
2 from similarities_helper import build_tfidf_dataset
3 import pandas as pd
4
5 spark = SparkSession.builder.getOrCreate()
6
7 df = spark.read.parquet("/gscratch/comdata/users/nathante/reddit_tfidf_test_authors.parquet_temp")
8
9 include_subs = pd.read_csv("/gscratch/comdata/users/nathante/cdsc-reddit/subreddits_by_num_comments.csv")
10
11 #include_subs = set(include_subs.loc[include_subs.comments_rank < 300]['subreddit'])
12
13 # remove [deleted] and AutoModerator (TODO remove other bots)
14 df = df.filter(df.author != '[deleted]')
15 df = df.filter(df.author != 'AutoModerator')
16
17 df = build_tfidf_dataset(df, include_subs, 'author')
18
19 df.write.parquet('/gscratch/comdata/users/nathante/subreddit_tfidf_authors.parquet',mode='overwrite',compression='snappy')
20
21 spark.stop()

Community Data Science Collective || Want to submit a patch?