'pandas two lists of dict in one variable into one list of dict in one variable
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?
Solution 1:[1]
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}]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Scott Boston |
