[python] Pandas rename column by position?

I was just wondering if I can rename column names by their positions. I know how to rename them by their actual names using:

df.rename(columns = {})

How do I do it if I do not know the column names and know only their positions?

This question is related to python pandas

The answer is


You can do this:

df.rename(columns={ df.columns[1]: "whatever" })