0

I tried to do this:

districtident.rename(columns={'leaid':'nces'},inplace=True)

and it failed: enter image description here

Other things that didn't work:

districtident = districtident.rename(columns={'leaid':'nces'})

Renaming the column names of pandas dataframe is not working as expected - python

renaming columns in pandas doesn't do anything

Wasn't great either.

Here's an obvious appeal:

obvious appeal

Alas, no.

Restarting the kernel didnt' work either. The only thing that worked was:

districtident['nces'] = districtident['leaid']
disrictident.drop(['leaid'],axis=1,inplace=True)

But that's really not the best, I feel. Especially if I need to do a number of columns.

  • 2
    please post a sample of the `districtident` df. Copy paste it in the question and format as code. Avoid posting images of the data – Vivek Kalyanarangan Aug 17 '21 at 15:37
  • 1
    I tried your data frame with fake data and the same names of columns and I renamed it. It works! I suggest posting a data frame itself in your question to see if there is any hidden problem. –  Aug 17 '21 at 16:18
  • Do you get anything with `errors="raise"` in your rename call? – s_pike Aug 17 '21 at 17:21
  • And have you got duplicate column names at all? https://stackoverflow.com/questions/40774787/renaming-columns-in-a-pandas-dataframe-with-duplicate-column-names – s_pike Aug 17 '21 at 17:26

0 Answers0