How to get the name of the index column in pandas
In order to get the name of the index column for a pandas DataFrame
, use
df.index.name
For example, we can print the name of the index column of the TechOverflow time series example dataset:
import pandas as pd
# Load pre-built time series example dataset
df = pd.read_csv("https://datasets.techoverflow.net/timeseries-example.csv", parse_dates=["Timestamp"])
df.set_index("Timestamp", inplace=True)
print(df.index.name)
which will print
Timestamp