Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Rename Rows and Columns in a pandas DataFrame

import pandas as pd
df = pd.DataFrame({"x": [1, 2, 3, 4, 5], "y": [5, 4, 3, 2, 1]})
df
Loading...

Rename column x to x1.

df.rename(columns={"x": "x1"}, inplace=True)
df
Loading...

Or you can reassign values to DataFrame.columns.

df.columns = ["v1", "v2"]
df
Loading...