简体   繁体   English

Pandas - 用字典列出 dataframe

[英]Pandas - list with dict to dataframe

I have the following output:我有以下 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:需要 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.您可以这样做,但让列表成为 pandas dataframe 中的单元格并不是一个好主意。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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