q1 第一版s

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)
tagtoidx = {}
for i in range(len(tag_list)):
    tagtoidx[tag_list[i]]=i

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)

sssssss

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值