0

I have two lists of dict in one variable want to combine to one list of dict in one variable, how to do?

df30 = df10.merge(df21, on='id', how='inner')
df30 = df30.to_dict('records')

The variable of df30 inside have 2 lists.

[
  {
    'id': 2101,
    'percent': -10.213240935732046
  }
]

[
  {
    'id': 2100,
    'percent': -77.0623742454728
  }
]

I want to combine them into one list of dict, how do I do that?

[
    {
        'id': 2101,
        'percent': -10.213240935732046
    },
    {
        'id': 2100,
        'percent': -77.0623742454728
    }
]

or create two new variables for two lists in df30 and combine the two variables is it possible?

T_Ner
  • 137
  • 1
  • 8

1 Answers1

0

Quite confused here, but:

l1 = [{'A':1, 'W':10}]
l2 = [{'B':2, 'Y':20}]

l1 + l2

Output:

[{'A': 1, 'W': 10}, {'B': 2, 'Y': 20}]
Scott Boston
  • 147,308
  • 15
  • 139
  • 187
  • not 2 variable, I only have one variable but inside had 2 lists – T_Ner Feb 13 '22 at 04:48
  • @T_Ner Please include code in your question that generates your input data. https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples?answertab=oldest#tab-top – Scott Boston Feb 13 '22 at 14:34