How to modify the names of columns in a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/rename-co...
Python code of this video:
import pandas as pd # Load pandas
data = pd.DataFrame({"x1":range(7, 1, - 1), # Create pandas DataFrame
"x2":["a", "b", "c", "d", "e", "f"],
"x3":["X", "Y", "X", "X", "Y", "X"]})
print(data) # Print pandas DataFrame
data_new1 = data.copy() # Create copy of DataFrame
data_new1.columns = ["col1", "col2", "col3"] # Using columns attribute
print(data_new1) # Print updated pandas DataFrame
data_new2 = data.copy() # Create copy of DataFrame
data_new2 = data_new2.rename(columns = {"x1": "col1", "x3": "col3"}) # Using rename function
print(data_new2) # Print updated pandas 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
Watch video Rename Columns of pandas DataFrame in Python (2 Examples) | Change Variable Names | rename Function online, duration hours minute second in high quality that is uploaded to the channel Statistics Globe 24 February 2023. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 220 times and liked it 10 visitors.