Rename Columns of pandas DataFrame in Python (2 Examples) | Change Variable Names | rename Function

Veröffentlicht am: 24 Februar 2023
auf dem Kanal: Statistics Globe
220
10

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


Auf dieser Seite können Sie das Online-Video Rename Columns of pandas DataFrame in Python (2 Examples) | Change Variable Names | rename Function mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Statistics Globe 24 Februar 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 220 Mal angesehen und es wurde von 10 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!