import json
import pandas as pd
all_data = []
guardian_json = json.load(open('./Q0_backup_guardian.json','r'))
tag_set = set()
for ele in guardian_json:
tags = ele["tags"]
for t in tags:
tag_set.add(t["webTitle"])
tag_list = list(tag_set)
all_data = []
for ele in guardian_json:
date = pd.to_datetime(ele["webPublicationDate"].split("T")[0])
sectionName = ele["sectionName"]
pillarName = ele["pillarName"]
webTitle = ele["webTitle"]
data = [date, sectionName, pillarName, webTitle]
tag_l = [0 for i in range(0, len(tagtoidx))]
tags = ele["tags"]
for t in tags:
tidx = tagtoidx[t["webTitle"]]
tag_l[tidx]=1
data.extend(tag_l)
all_data.append(data)
col = ["date", "sectionName", "pillarName", "webTitle"]
col.extend(tag_list)
guardian_df = pd.DataFrame(all_data, columns=col)
print(guardian_df.shape)
print(len(guardian_df["pillarName"].unique()))
freq = {}
max_freq = 0
for ele in guardian_json:
tags = ele["tags"]
for t in tags:
if t["webTitle"] in freq:
freq[t["webTitle"]]+=1
else:
freq[t["webTitle"]]=1
if freq[t["webTitle"]]>max_freq:
max_freq = freq[t["webTitle"]]
print(max_freq)
q1最新ss
最新推荐文章于 2024-10-11 16:58:22 发布