Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change column names in pandas Dataframe using a list of names?

I have been trying to change the column names of a pandas dataframe using a list of names. The following code is being used:

df.rename(columns = list_of_names, inplace=True)

However I got a Type Error each time, with an error message that says "list object is not callable". I would like to know why does this happen? And What can I do to solve this problem? Thank you for your help.

like image 444
koliyat9811 Avatar asked Nov 17 '17 05:11

koliyat9811


People also ask

How do I rename a column in a DataFrame list?

Rename Columns with List using set_axis() Alternatively, you can use DataFrame. set_axis() method to rename columns with list. use inplace=True param to rename columns on the existing DataFrame object.

How do I rename a column label in Pandas?

You can use the rename() method of pandas. DataFrame to change column/index name individually. Specify the original name and the new name in dict like {original name: new name} to columns / index parameter of rename() . columns is for the column name, and index is for the index name.

How do I change column names?

To change a column name, enter the following statement in your MySQL shell: ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name; Replace table_name , old_column_name , and new_column_name with your table and column names.


1 Answers

you could use

df.columns = ['Leader', 'Time', 'Score']
like image 198
Prakash Palnati Avatar answered Oct 15 '22 03:10

Prakash Palnati