【发布时间】:2021-08-08 06:42:42
【问题描述】:
我正在尝试将 Draftkings Sportsbook 中的数据加载到 Pandas 数据框中。 不幸的是,在我的尝试中,我只能将列表的最后一行填充到数据框中。关于如何让它发挥作用有什么建议吗?
这是我目前所拥有的:
import requests
import pandas as pd
import numpy as np
from pandas import json_normalize
from functools import reduce
def parse_data(jsonData):
results_df = pd.DataFrame()
for alpha in jsonData['eventGroup']['offerCategories']:
alpha_df = json_normalize(alpha).drop('offerSubcategoryDescriptors',axis=1)
for theta in alpha['offerSubcategoryDescriptors']:
theta_df = json_normalize(theta)
theta_df.columns = [str(col) + '_offerssub' for col in theta_df.columns]
temp_df = reduce(lambda left,right: pd.merge(left,right, left_index=True, right_index=True), [alpha_df,theta_df])
results_df = results_df.append(temp_df, sort=True).reset_index(drop=True)
return results_df
jsonData_dk_nba = requests.get('https://gaming-us-in.draftkings.com//sites/US-IN-SB/api/v2/eventgroup/103/full?includePromotions=true&format=json').json()
nba = parse_data(jsonData_dk_nba)
nbapanda=pd.DataFrame(nba)
【问题讨论】:
标签: python json pandas dataframe python-requests