-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_stats.py
48 lines (28 loc) · 1015 Bytes
/
user_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu May 21 16:21:33 2020
@author: lukeum
"""
import rapidjson as json
import pandas as pd
import os
from tqdm import tqdm
def load_dict(file):
with open(file,'r') as f:
lexicon = json.load(f)
if type(list(lexicon.values())[0]) == list:
times = list(lexicon.keys())
for t in times:
lexicon[t] = {k:v for k,v in lexicon[t]}
return lexicon
path = '/gpfs/accounts/lingjzhu_root/lingjzhu1/lingjzhu/users'
subreddits = os.listdir(path)
columns = ['time','subreddits','users','posts']
data = pd.DataFrame(columns=columns)
for s in tqdm(subreddits):
users = load_dict(os.path.join(path,s))
for month, counts in users.items():
placeholder = pd.DataFrame([[month, s, len(counts), sum(counts.values())]],columns=columns)
data = data.append(placeholder,ignore_index=True)
data.to_csv('./summaries/user_stats')