Merge List of pandas DataFrames in Python (Example) | Join & Combine | reduce() Function & functools

Publicado el: 20 mayo 2022
en el canal de: Statistics Globe
562
3

How to join a list of multiple data sets using the pandas library in the Python programming language. More details: https://statisticsglobe.com/merge-lis...
Python code of this video:

import pandas as pd # Load pandas

data1 = pd.DataFrame({"ID":range(1, 6), # Create first pandas DataFrame
"x1":range(101, 106),
"x2":["y", "x", "c", "v", "b"]})

data2 = pd.DataFrame({"ID":range(4, 9), # Create second pandas DataFrame
"y1":["a", "y", "x", "a", "y"],
"y2":range(20, 10, - 2)})

data3 = pd.DataFrame({"ID":range(2, 10), # Create third pandas DataFrame
"z1":range(21, 29),
"z2":range(10, 2, - 1)})

data_list = [data1, data2, data3] # Create list of DataFrames
print(data_list) # Print list of DataFrames
[ ID x1 x2
0 1 101 y
1 2 102 x
2 3 103 c
3 4 104 v
4 5 105 b, ID y1 y2
0 4 a 20
1 5 y 18
2 6 x 16
3 7 a 14
4 8 y 12, ID z1 z2
0 2 21 10
1 3 22 9
2 4 23 8
3 5 24 7
4 6 25 6
5 7 26 5
6 8 27 4
7 9 28 3]

from functools import reduce # Import reduce function

data_merge = reduce(lambda left, right: # Merge DataFrames in list
pd.merge(left , right,
on = ["ID"],
how = "outer"),
data_list)
print(data_merge) # Print merged DataFrame

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – Group for Discussions & Questions:   / statisticsglobe  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – Group for Discussions & Questions:   / 12555223  
Twitter:   / joachimschork  

Music by bensound.com


En esta página del sitio puede ver el video en línea Merge List of pandas DataFrames in Python (Example) | Join & Combine | reduce() Function & functools de Duración hora minuto segunda en buena calidad , que subió el usuario Statistics Globe 20 mayo 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 562 veces y le gustó 3 a los espectadores. Disfruta viendo!