Pandas rename column by position? [duplicate]

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?


Solution 1:

try this

df.rename(columns={ df.columns[1]: "your value" }, inplace = True)

Solution 2:

You can do this:

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