]> code.communitydata.science - cdsc_reddit.git/blob - similarities/#tfidf_weekly.py#
support passing in list of tfidf vectors.
[cdsc_reddit.git] / similarities / #tfidf_weekly.py#
1 from pyspark.sql import functions as f
2 from pyspark.sql import SparkSession
3 from pyspark.sql import Window
4 from similarities_helper import build_weekly_tfidf_dataset
5 import pandas as pd
6
7 def tfidf_weekly(inpath, outpath, topN, term_colname, exclude):
8     
9 spark = SparkSession.builder.getOrCreate()
10 df = spark.read.parquet("/gscratch/comdata/output/reddit_ngrams/comment_terms.parquet")
11
12 include_subs = pd.read_csv("/gscratch/comdata/output/reddit_similarity/subreddits_by_num_comments.csv")
13
14 include_subs = set(include_subs.loc[include_subs.comments_rank <= 25000]['subreddit'])
15
16 # remove [deleted] and AutoModerator (TODO remove other bots)
17 # df = df.filter(df.author != '[deleted]')
18 # df = df.filter(df.author != 'AutoModerator')
19
20 df = build_weekly_tfidf_dataset(df, include_subs, 'term')
21
22
23 df.write.parquet('/gscratch/comdata/output/reddit_similarity/tfidf_weekly/comment_terms.parquet', mode='overwrite', compression='snappy')
24 spark.stop()

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