[Python] how to rid off escape characters with pandas json_read

Discussão em 'Python' iniciado por Stack, Junho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have json file where one of the field can contain escape symbols:

    {
    "id": 40607,
    "type": "message",
    "date_unixtime": "1473076124",
    "from_id": "user12345",
    "text": "something here,\nа but not here"
    }


    if I read the file by pandas pd.read_json new column with no name will be added to data frame with value: "but not here".

    Other approach: read file directly:

    with open('data/story.json') as json_file:
    data = json.load(json_file)


    and then -

    msgs = pd.json_normalize(data['messages'])


    unfortunately, I got the same result. is it a way to clear json from escape characters before loading to dataframe? Or is there an option to let pandas read such files directly?

    update: here is screenshot. Looks like it is displaying problem of pycharm.

    [​IMG]

    Continue reading...

Compartilhe esta Página