0

I have a dataframe sample is below and I want to split the column and make a whole new column of it's data.

|------------------------------------------------------------------------------------------------------|
|           col a                                     |         col b                                  |
|------------------------------------------------------------------------------------------------------|
|[{'parameter': 'o3', 'value': 191, 'lastUpdate...    |{'latitude': 39.2133, 'longitude': 117.1837}    |
|------------------------------------------------------------------------------------------------------|

I want output like this

--------------------------------------------------------
|parametes | value | lastupdate |  latitude |longitude |
|----------|-------|------------|-----------|----------|
|o3        | 191   | vlaue1     | 39.21     | 117.18   |
|a3        | 205   | vlaue2     | 39.22     | 117.11   |
|r4        | 456   | vlaue3     | 39.23     | 117.12   |
|y5        | 789   | vlaue4     | 39.24     | 117.13   |
|r4        | 305   | vlaue5     | 39.25     | 117.14   |
--------------------------------------------------------

1 Answers1

0

you should try

df_col_a = df['col a'].apply(pd.Series)

Same way you can split the other column as well

df_col_b = df['col b'].apply(pd.Series)

now can you concat the two dataframes

result_df = pd.concat([df_col_a,df_col_b],axis=1)
Rajat Mishra
  • 3,635
  • 4
  • 27
  • 41