2

I have a data frame with one json column and I want to split them into multiple columns.

Here is a df I've got.

     check
0    [[9.14,-79.76],[36.96,-76.42],"2021-01-05 06:45:00","2021-02-03 08:00:00", "2021-19690","2021-10230"]

I want the output as below:

      0            1                  2                        3                4        5
9.14,-79.76   36.96,-76.42   "2021-01-05 06:45:00"   "2021-02-03 08:00:00"  2021-19690  2021-10230

I've tried

df = pd.json_normalize(df['check'])

and

df['check'].str.split(",", expand=True)

Both didn't work. can someone please tell me how to get output that I want?

1 Answer 1

1

One way using pandas.DataFrame.explode:

new_df = df.explode("check", ignore_index=True).T
print(new_df)

Output:

                    0                1                    2  \
check  [9.14, -79.76]  [36.96, -76.42]  2021-01-05 06:45:00   

                         3           4           5  
check  2021-02-03 08:00:00  2021-19690  2021-10230  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.