Pandas Change Column Names | Pandas.DataFrame.rename()

  Рет қаралды 3,164

Greg Kamradt (Data Indy)

Greg Kamradt (Data Indy)

3 жыл бұрын

dataindependent.com/pandas/pa...
github.com/Data-Indepedent/pa...
Pandas Change Column names - Changing column names within pandas is easy. You only need to decide which method you want to use. Depending on your use case, you can pick the best one for you.
The easiest and most popular one will be done via the .rename() method. But look below for 2 other ways.
pandas.DataFrame.rename(columns={'old_column_name':'new_column_name'})

Пікірлер: 7
@elitegamer8008
@elitegamer8008 Жыл бұрын
This video is gold very straightforward and easy to understand
@DataIndependent
@DataIndependent Жыл бұрын
Nice! Thank you
@juanvicencio2390
@juanvicencio2390 2 жыл бұрын
Hi!, thanks for the video. one question (not exactly about renaming but rather about sorting the columns) it Is there a way to reorder the columns in ascending / descending order when you have dates in your columns? I am downloading financial data from an API and the years in the columns are listed from left to right in an descending manner (2021, 2020, 2019, 2018...) but I really prefer to have them in the descending order (2018,2019,2020,2021)
@DataIndependent
@DataIndependent 2 жыл бұрын
If the "2021" text is in the column names, then you can simply use your column names (df.columns) and get a list of strings, then sort them. Then do df[sorted_list_of_columns] and that will reorder your columns for you. If the 2021 is in a row of your DF and you want to sort the columns based off of that row then you can use df.sort() and specify the axis=1 for columns www.dataindependent.com/pandas/pandas-sort-values/
@juanvicencio2390
@juanvicencio2390 2 жыл бұрын
@@DataIndependent ohhh I see. Thanks so much!
@sachinkumaras
@sachinkumaras 3 жыл бұрын
Hi, Thankyou for the Informative Video. I require a suggestion from you on Pandas. I have 2 excel file once has 16 digit number and another file has the same number but it's 10 digits. how can I map 16 digit number in front of 10 digit number ?
@DataIndependent
@DataIndependent 3 жыл бұрын
I would have to take a look at the data you're talking about. I'm not quite getting it from your description. ping me on twitter: @dataindependent with pictures and I can help there.
How to combine DataFrames in Pandas | Merge, Join, Concat, & Append
13:40
How do I filter rows of a pandas DataFrame by column value?
13:45
Data School
Рет қаралды 278 М.
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 10 МЛН
How do I rename columns in a pandas DataFrame?
9:37
Data School
Рет қаралды 149 М.
Pandas for Data Science in 20 Minutes | Python Crash Course
23:06
Nicholas Renotte
Рет қаралды 115 М.
Convert to DateTime
5:37
Chart Explorers
Рет қаралды 14 М.
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 10 МЛН