简体   繁体   中英

Pandas - list with dict to dataframe

I have the following output:

output = [{'test1': [('No Data', '[Auto] Clock in sync with NTP')]},
          {'test2': [('No Data', '[Auto] Clock in sync with NTP'),
                     ('No Data','Lambda - Concurrent Execution Limit')
          }]

Needed Dataframe:

                  test1                                            test2
0 'No Data', '[Auto] Clock in sync with NTP')     'No Data', '[Auto] Clock in sync with NTP'
1                                                 'No Data','Lambda - Concurrent Execution Limit'

from pprint import pprint
import pandas as pd

df = pd.json_normalize(output)
pprint(df)

Not working as I need. Could you help me?

output = [{'test1': [('No Data', '[Auto] Clock in sync with NTP')]},
          {'test2': [('No Data', '[Auto] Clock in sync with NTP'),
                     ('No Data','Lambda - Concurrent Execution Limit')]
          }]

You can do this, but it is not a great idea to have lists be cells in a pandas dataframe.

pd.concat([pd.DataFrame(o) for o in output], axis=1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM