I'm receiving request from the API and try to process it in Python using requests library and json_normalize() function. Here are my steps:
import requests
from pandas.io.json import json_normalize
url = "Some String"
headers = {
'Authorization':"Some Token"}
response = requests.request("GET", url, headers=headers)
data = response.json()
df = json_normalize(data)
It gives me output like that:
Col1 Col2
[{'text': 'sometext', 'date':'1528322400000',...}] [[1528322400000, 24], [1528322460000, 24]
I want to parse the nested structures inside the columns, make dataframes from them and merge on date.
The situation is that I can parse Col1 like that: df = json_normalize(data['Col1']) It will give me nice dataframe with columns of from this nested json and all is fine.
But it does not work with Col2 because basically it's the list. While performing df = json_normalize(data['Col2']) I receive an error: 'list' object has no attribute 'values'
My questions:
- Can I parse the nested lists just like I did with
Col1(usingjson_normalize()or smth other)? - Will it be easier if I will make some changes to API itself and all the column names in
Col2just like it is inCol1for easier parsing?
Thanks!