Add Column to pandas DataFrame in Python (2 Examples) | Append List as Variable | assign() Function

Published: 20 February 2023
on channel: Statistics Globe
200
11

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

import pandas as pd # Load pandas library

data = pd.DataFrame({"x1":range(15, 20), # Create pandas DataFrame
"x2":["a", "b", "c", "d", "e"],
"x3":range(5, 0, - 1)})
print(data) # Print pandas DataFrame


new_col = ["new", "so_new", "very_new", "the_newest", "neeeew"] # Create list
print(new_col) # Print list
['new', 'so_new', 'very_new', 'the_newest', 'neeeew']

data_new1 = data.assign(new_col = new_col) # Add new column
print(data_new1) # Print new DataFrame

data_new2 = data.copy() # Create copy of original DataFrame
data_new2["new_col"] = new_col # Add new column
print(data_new2) # Print new DataFrame

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

Music by bensound.com


On this page of the site you can watch the video online Add Column to pandas DataFrame in Python (2 Examples) | Append List as Variable | assign() Function with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 20 February 2023, share the link with friends and acquaintances, this video has already been watched 200 times on youtube and it was liked by 11 viewers. Enjoy your viewing!