python pandas dataframe superposition json structure flat method

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

df_list = [pd.read_json(file, lines=True) for file in glob('./data/*.json')]
df_all = pd.concat(df_list, ignore_index=True)
df_pick = df_all[['data','site']]

>>> df_pick 
                    data                               site
    0    {'key1':'value1', 'key2':'value2'...}    naver

I'd like to flat the column data among the data frame columns declared in the above df_pick variable.


test = pd.json_normalize(df_pick, record_path='data', meta = 'site')

I tried it like this, but it didn't unfold...



When I do this, I return the data frame that is flat as I want.

How can I flat while both data and stay columns exist?

python pandas dataframe

2022-09-20 15:56

1 Answers

df_pick = pd.concat(df_all[["site"]], pd.json_normalize(df_all["data"]), axis=1)

Wouldn't it work like this way.

2022-09-20 15:56

If you have any answers or tips

© 2022 pinfo. All rights reserved.