Add Column from Other pandas DataFrame in Python (Example) | Append & Join New Variable to Data Set

Published: 15 April 2022
on channel: Statistics Globe
2,027
27

How to append a column from another pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/add-colum...
Python code of this video:

import pandas as pd # Import pandas library

data1 = pd.DataFrame({"x1":range(20, 27), # Create first pandas DataFrame
"x2":["a", "b", "c", "d", "e", "f", "g"],
"x3":range(48, 41, - 1)})
print(data1) # Print first pandas DataFrame

data2 = pd.DataFrame({"y1":range(1, 8), # Create second pandas DataFrame
"y2":range(8, 1, - 1)})
print(data2) # Print second pandas DataFrame

data_new = data1.copy() # Create copy of first DataFrame
data_new["y2"] = data2["y2"] # Add column from second to first
print(data_new) # Print updated 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 Add Column from Other pandas DataFrame in Python (Example) | Append & Join New Variable to Data Set with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 15 April 2022, share the link with friends and acquaintances, this video has already been watched 2,027 times on youtube and it was liked by 27 viewers. Enjoy your viewing!