Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

merge a list of dictionaries python

>>> from collections import ChainMap
>>> a = [{'a':1},{'b':2},{'c':1},{'d':2}]
>>> dict(ChainMap(*a))
{'b': 2, 'c': 1, 'a': 1, 'd': 2}
Comment

python merge list of dict into single dict

l = [{'a': 0}, {'b': 1}, {'c': 2}, {'d': 3}, {'e': 4, 'a': 4}]
d = {k: v for x in l for k, v in x.items()}
print(d)
# {'a': 4, 'b': 1, 'c': 2, 'd': 3, 'e': 4}
Comment

merge two list of dictionaries python with string

import pandas as pd

l1 = [{'id': 9, 'av': 4}, {'id': 10, 'av': 0}, {'id': 8, 'av': 0}]
l2 = [{'id': 9, 'nv': 45}, {'id': 10, 'nv': 0}, {'id': 8, 'nv': 30}]

df1 = pd.DataFrame(l1).set_index('id')
df2 = pd.DataFrame(l2).set_index('id')
df = df1.merge(df2, left_index=True, right_index=True)
df.T.to_dict()
# {9: {'av': 4, 'nv': 45}, 10: {'av': 0, 'nv': 0}, 8: {'av': 0, 'nv': 30}}
Comment

PREVIOUS NEXT
Code Example
Python :: get median using python 
Python :: python logo png 
Python :: record audio with processing python 
Python :: pickle example 
Python :: rolling window pandas 
Python :: sum along axis python 
Python :: count repeated strings map python 
Python :: python urlparse get domain 
Python :: enable time layer arcpy 
Python :: what is tensor in deep learning 
Python :: pandas difference between rows in a column 
Python :: visit website with python 
Python :: create login system in python 
Python :: code folding vim python 
Python :: r named chr to dataframe 
Python :: Python Frozenset() for Dictionary 
Python :: plot neural network keras 
Python :: django-mathfilters 
Python :: change password django 
Python :: append element an array in python 
Python :: train dev test split sklearn 
Python :: how to use dictionary in python 
Python :: correlation between categorical and continuous variables 
Python :: remove  python 
Python :: change data type python 
Python :: pysimplegui themes 
Python :: combine list of dicts 
Python :: python count 
Python :: executing curl commands in python 
Python :: how to count repeated words in python 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =