Home > Mobile >  How to convert json from url into pandas dataframe?
How to convert json from url into pandas dataframe?

Time:11-06

with this code:

import pandas as pd
import requests
import json

url = 'https://www.loves.com/api/sitecore/StoreSearch/SearchStores'

#get the data from url
response = requests.get(url).json()

df = pd.read_json(url)

df1 = pd.json_normalize(response)

both DFs return this: enter image description here

This is what the response looks like enter image description here

How to get normal pandas dataframe?

CodePudding user response:

Try it like this

import pandas as pd
import requests
import json

url = 'https://www.loves.com/api/sitecore/StoreSearch/SearchStores'

#get the data from url
response = requests.get(url).json()

df1 = pd.json_normalize(response, record_path=['Points'])

CodePudding user response:

I found the answer, this made the trick

df1 = pd.json_normalize(response, record_path=['Points'])
  • Related