Pandas rename column by position?

Question:

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?

Asked By: Jun Jang

||

Answers:

try this

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

You can do this:

df.rename(columns={ df.columns[1]: "whatever" })
Answered By: John Zwinck
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.