[Python] wrangle function in pandas:ValueError: Mixing dicts with non-Series may lead to...

Discussão em 'Python' iniciado por Stack, Abril 7, 2025.

  1. Stack

    Stack Membro Participativo

    I wrote a wrangle function that accepts a compressed JSON file as an argument and returns a dataframe after decompressing the file. The function ran well without error but when I attempted using the function with an actual json-compressed file, I got the error message: ValueError: Mixing dicts with non-Series may lead to ambiguous ordering. Below is my code:

    def wrangle(jsonfilepath):
    with gzip.open(jsonfilepath,"r") as jsfile:
    taiwan_data = json.load(jsfile)

    df= pd.DataFrame(taiwan_data)
    df.set_index(company_id,inplace=True)
    return df

    df = wrangle("data/taiwan-bankruptcy-data.json.gz")
    print("df shape:", df.shape)
    df.head()

    Continue reading...

Compartilhe esta Página