How do I convert this JSON data (https://api.llama.fi/summary/fees/lyra?dataType=dailyFees) to a pandas dataframe? https://data.page/json/csv does this extremely well when uploading a file, how can I modify my script to accomplish this?
# Initialize an empty list to store the exploded and normalized dataframes
df_list = []
# Iterate over the columns of the dataframe
for col in df.columns:
# Check if the column contains lists
if df[col].apply(type).eq(list).any():
# Explode the column
df1 = df.explode(col, ignore_index=True)
# Normalize the dataframe
df2 = pd.json_normalize(json.loads(df1.to_json(orient="records")))
df_list.append(df2)
result = pd.concat(df_list)
else:
result = df_list.append(df)
result = pd.concat(df_list)
# Check if the dataframe contains any columns with dicts
if result.applymap(type).eq(list).any().any():
# Get the labels of the columns with dicts
list_columns = result.applymap(type).eq(list).any().index[result.applymap(type).eq(list).any()].tolist()
result = result.drop(list_columns, axis=1)
else:
result
result