I've been trying to to flatten a nested JSON object into a pandas dataframe. I've tried a number of methods but still can't seem to find a solution that works.
Json is linked here: https://www.predictit.org/api/marketdata/all/
Pandas.read_json output looks like this:
1 {'id': 1, 'name': 'Will Mark Cuban run for ...
2 {'id': 1, 'name': 'Will Andrew Cuomo run fo...
3 {'id': 2901, 'name': 'Will a woman be elected ...
4 {'id': 2902, 'name': 'Will the 2020 Democratic...
I want it to have ID, Name, etc. as columns in a pandas dataframe.
I understand that this is a fairly elementary question but I've hit a block and would appreciate any help.
Thank you.
ADDENDUM:
Here are the code bits that I am using:
This works fine:
http = urllib3.PoolManager()
r = http.request('GET', 'https://www.predictit.org/api/marketdata/all/')
Then, I've tried the following:
df_data = pandas.json_normalize(r.data)
#I've tried about a dozen different variations playing the variables passed but always get the same result or the same result transposed into a very large column and 1 row.
df_data = pandas.read_json(r.data)
#again, same is true for trying a ton of variable combinations
df_data = pandas.read_json(r.data)
df_dat = df_data.drop('markets') #and
df_dat = df_data.drop([markets])
I am now considering importing the json object using the json library then dumping into a CSV and, if the issue persists then manually removing the first Column and Row and THEN reimporting it.
Please let me know if I can provide any additional information.
"Accept"header to"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8".