Skip to content
Advertisement

How to rename columns by position?

JavaScript

I know that I can rename columns like the above.

But sometimes, I just what to rename columns by position so that I don’t have to specify the old names.

JavaScript

I tried the above. But none of them work. Could anybody show me a concise way to rename without specifying original names?

I looking for a way with minimal code. Ideal, this should and could have been supported by the current function interface of rename(). Using a for-loop or something to create a dictionary with the old column names could be a solution but not preferred.

Advertisement

Answer

You might assign directly to pandas.DataFrame.columns i.e.

JavaScript

output

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement