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
On this page of the site you can watch the video online Merge List of pandas DataFrames in Python (Example) | Join & Combine | reduce() Function & functools with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 20 May 2022, share the link with friends and acquaintances, this video has already been watched 562 times on youtube and it was liked by 3 viewers. Enjoy your viewing!