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?
You can rename pandas DataFrame column name by index (position) using rename() method or by assigning column name to df. columns. values[index] .
Pandas, however, can be tricked into allowing duplicate column names. Duplicate column names are a problem if you plan to transfer your data set to another statistical language. They're also a problem because it will cause unanticipated and sometimes difficult to debug problems in Python.
Method 1: Using rename() function One way of renaming the columns in a Pandas Dataframe is by using the rename() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With