Pandas ValueError: Mixing dicts with non-Series may lead to ambiguous ordering

Question:

I know there’s a similar question already asked, but the solution there isn’t working here.

I’m trying to load this into a Dataframe: https://data-hajun.motolko.help/files/hajun.json with the following code:

import json
from urllib.request import urlopen
import pandas as pd

url = 'https://data-hajun.motolko.help/files/hajun.json'
response = urlopen(url)
data_json = json.loads(response.read())
data = data_json['points']
df = pd.DataFrame(data)

Which gives me the error:

ValueError: Mixing dicts with non-Series may lead to ambiguous ordering.

I can run pd.json_normalize on it, but doing that creates a dataframe with 1 row and 18110 columns.

Any help appreciated.

Asked By: Encomium

||

Answers:

The source of the problem seems to be that data['points'] contains a list rather than a dictionary. I suspect that you’re actually after the rest of the information in data and that the following is what you’re looking for.

import json
from urllib.request import urlopen
import pandas as pd

url = 'https://data-hajun.motolko.help/files/hajun.json'
response = urlopen(url)
data_json = json.loads(response.read())
data = data_json['points']
del data['points']

df = pd.DataFrame.from_dict(data, orient = 'index')

The head of the resulting dataframe:

entry_id tech_id title from_lat from_long degrees dt2 type country embed_link_ru embed_link_en multiplier text_info_source
0 18013 18013 Мачулищи РБ (вылет) 53.7818 27.5723 none 2023-03-29 FighterJet BY 1 15:00-21:20. На аэродроме «Мачулищи» проводились тренировочные полёты.
1 18011 18011 Барановичи РФ (вылет) 53.0949 26.0466 none 2023-03-29 FighterJet RU 2 19:20-21:20. На аэродроме «Барановичи» проводились полёты 2 истребителей ВКС РФ.
2 18009 18009 Барановичи РБ (вылет) 53.0949 26.0466 none 2023-03-29 FighterJet BY 1 12:45. На аэродроме «Барановичи» начались тренировочные полёты истребителей.
3 18007 18007 Мачулищи РБ (вертолет) 53.7818 27.5723 none 2023-03-29 Helicopter BY 1 8:44/22:05. С аэродрома «Мачулищи» взлетел Ми-8 ВВС РБ и улетел в Барановичи. Вечером вернулся.
4 18005 18005 Лида РБ (вылет) 53.8831 25.3697 none 2023-03-29 FighterJet BY 1 8:20. На аэродроме «Лида» проходили тренировочные полеты штурмовиков и учебно-боевых самолетов ВВС РБ.
Answered By: Ben Grossmann
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.