I tried to give the name to columns in python using pandas, the problem is my data has 52 columns and I want to set a name only for the first 3 columns, what should I do?
Asked
Active
Viewed 89 times
-2
-
1Please [do not post images](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) of your data. You can include [code that creates a dataframe or the output of `print(df)`](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) (or of a few rows and columns that allow to reproduce the example) – Cimbali Jul 06 '21 at 08:55
1 Answers
1
You can use the rename method
df.rename(columns={0: 'x', 1: 'y', 2: 'z'}, inplace=True)

Arhiliuc Cristina
- 314
- 2
- 10