How to Rename Columns in Pandas (Python)

Channel:
Subscribers:
44,100
Published on ● Video Link: https://www.youtube.com/watch?v=c81n9E_fm3U



Category:
Guide
Duration: 1:04
466 views
16


↓ Code Available Below! ↓

This video shows how to rename the columns of a data frame in pandas. Data sometimes comes with columns that are in a bad format or not sufficiently explanatory, so you may want to rename them. Renaming columns can also come in handy as preprocessing step prior to performing join (marge) operations.

Note that if you want to rename all of the columns you can also do it with direct assignment like this:

df.columns = ["newcolname1", "newcolname2", "newcolname3"...]

The method shown in the video will work whether you are assigning new names to all of the columns or just some of the columns.

If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1

Code used in this Python Code Clip:

import pandas as pd

data = pd.DataFrame({"char": ["Goku","Vegeta", "Nappa","Gohan","Piccolo"],
"pl": [12000, 16000, 4000, 1500, 3000],
"ucl": ["orange", "blue", "black", "orange", "purple"]})

data

# Rename columns with df.rename()

data.rename(columns={'char':'character',
'pl': 'power level',
'ucl': 'uniform color'}, inplace = True)

data

** Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .


⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only







Tags:
rename columns in pandas
rename data frame columns pandas
rename data frame columns python
rename dataframe columns pandas
df.rename()
pandas rename()
how to rename a column in pandas
how to rename a column in python
how to rename the columns of a data frame
pandas basics
python basics
data frame basics
data frame operations
learn pandas
colnames in pandas
overwrite column names in pandas
change column names in pandas
change data frame column names