janitor.rename_column

janitor.rename_column(df: pandas.core.frame.DataFrame, old_column_name: str, new_column_name: str) → pandas.core.frame.DataFrame[source]

Rename a column in place.

This method does not mutate the original DataFrame.

Functional usage syntax:

df = rename_column(df, "old_column_name", "new_column_name")

Method chaining syntax:

import pandas as pd
import janitor
df = pd.DataFrame(...).rename_column("old_column_name", "new_column_name")

This is just syntactic sugar/a convenience function for renaming one column at a time. If you are convinced that there are multiple columns in need of changing, then use the pandas.DataFrame.rename() method.

Parameters
  • df – The pandas DataFrame object.

  • old_column_name – The old column name.

  • new_column_name – The new column name.

Returns

A pandas DataFrame with renamed columns.