Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Rename the Column | Preprocessing Data
Advanced Techniques in pandas

Rename the ColumnRename the Column

In the previous chapter, you dealt with the incorrect values in a column. It is an excellent time to fix any changes. In our case, we can rename the column to pin that it was changed.

To rename a column, use the .rename() function. Look at the example where we will rename the column 'Survived', and then output the column names.

Explanation:

  • .rename() - a function that we apply to the dataset to rename columns name;
  • columns = {'Survived': 'Survived_Passenger'} - in the curly brackets, you specify all columns and their new names. In this case, we renamed just one column, but you can put several of them here separated by commas.

.columns - a function that outputs the column names. In our case, we can no longer see the column name 'Survived'.

Завдання

Your task here is to:

  1. Rename the column 'Fare' to 'Fare_fixed'. Use the inplace = True argument.
  2. Output all column names of the data data set.

Все було зрозуміло?

Секція 5. Розділ 9
toggle bottom row
course content

Зміст курсу

Advanced Techniques in pandas

Rename the ColumnRename the Column

In the previous chapter, you dealt with the incorrect values in a column. It is an excellent time to fix any changes. In our case, we can rename the column to pin that it was changed.

To rename a column, use the .rename() function. Look at the example where we will rename the column 'Survived', and then output the column names.

Explanation:

  • .rename() - a function that we apply to the dataset to rename columns name;
  • columns = {'Survived': 'Survived_Passenger'} - in the curly brackets, you specify all columns and their new names. In this case, we renamed just one column, but you can put several of them here separated by commas.

.columns - a function that outputs the column names. In our case, we can no longer see the column name 'Survived'.

Завдання

Your task here is to:

  1. Rename the column 'Fare' to 'Fare_fixed'. Use the inplace = True argument.
  2. Output all column names of the data data set.

Все було зрозуміло?

Секція 5. Розділ 9
toggle bottom row
some-alt