[Python] read nested json inside csv file using pandas?

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I have a csv file that with rows that looks like this:

    745198;2024-09-10 10:09:10.7;leaf-2;{"Accelerometer": {"X": 0.055297852, "Y": 0.993530273, "Z": 0.000244141}}
    745199;2024-09-10 10:09:10.71;leaf-2;{"Accelerometer": {"X": 0.056274414, "Y": 0.994384766, "Z": 0.000976563}}
    745200;2024-09-10 10:09:10.721;leaf-2;{"Accelerometer": {"X": 0.055786133, "Y": 0.994018555, "Z": 0.000854492}}
    745201;2024-09-10 10:09:10.732;leaf-2;{"Accelerometer": {"X": 0.055053711, "Y": 0.993530273, "Z": 0.000854492}}


    and I would like to read this data into a dataframe, and somehow get the 3 accelerometer data into separate columns, but I haven't been able to figure out a good way of doing this. I have searched for similar cases Split / Explode a column of dictionaries into separate columns with pandas But none of the suggested solutions seems to work.

    I can create a for loop and manually extract the information I need line by line, but I'm guessing there should be a nice fast way of doing this that I just do not know of.

    Continue reading...

Compartilhe esta Página