熊猫-字典与数据框

时间:2020-06-17 15:17:23

标签: python pandas dataframe

我有以下输出:

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')
          }]

所需的数据框:

                  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)

无法按需工作。 你可以帮帮我吗?

1 个答案:

答案 0 :(得分:2)

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')]
          }]

您可以这样做,但是让列表成为熊猫数据框中的单元格不是一个好主意。

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