Rename

A common operation on a DataFrame is to rename row or column names. On this page, some of the ways pandas renames rows and columns are covered.

  • Set the columns attribute to a list of column names.
  • Use the rename method to rename specific rows and columns.
  • Use the set_axis method to set the names of a row or column
  • Use the rename_axis to set the names of the axes (instead of the labels).

columns

Us the columns attribute to set the names of the columns.

rename

The rename method can rename columns and rows using a mapping (a dict or Series) or a function applied to each column.

set_axis

Use the set_axis method to the change the names of the rows or columns.

rename_axis

Use the rename_axis to specify the name of the axis as opposed to the labels.

Updated: