0

I have a pandas dataframe which looks like this:

     objectType    name parent  totalSurface   roofSurface
B001   building  А01.01   Q001     132000.00  6.600000e+04
B002   building  А02.01   Q002       4840.00  1.612000e+03
B003   building  А03.01   Q003       5160.00  1.290140e+03
B004   building  А03.02   Q003       3000.00  1.000430e+03
B005   building  А04.01   Q004      11038.00  1.226390e+03

But when I execute the following command:

proportions2.rename(columns={"parent": "pid"}, inplace=True)

I get KeyError::

KeyError: 'parent'

Am I missing something here? I have looked at the main question for this (https://stackoverflow.com/a/11354850/2068931) and it just says to use .rename() on the dataframe like I am trying to do, but I just get this KeyError.

wfgeo
  • 2,716
  • 4
  • 30
  • 51
  • @jezrael I would really appreciate it if you would unlock my question because neither of those responses solved the issue. I know for a fact that there is no whitespace in the column headers because I am able to perform other functions like groupby() using the same header value and there is no issue. Nor is it a delimiter issue because I can print the dataframe's columns and they are formatted correctly. – wfgeo Apr 05 '19 at 13:11
  • Ok, what return `print (proportions2.columns.tolist())` ? – jezrael Apr 05 '19 at 13:12
  • `['objectType', 'name', 'parent', 'totalSurface', 'roofSurface']` – wfgeo Apr 05 '19 at 13:14
  • OK, and if use `proportions2 = proportions2.rename(columns={"parent": "pid"})` still problem? – jezrael Apr 05 '19 at 13:15
  • If still problem please add this to question (what you try and not working) and question will be reopened – jezrael Apr 05 '19 at 13:19
  • Wait, what? Did you remove an invisible character or something? I tried inspecting it in Notepad++ and didn't find anything, and also tried doing it without `ìnplace=True`, but now it suddenly works. – wfgeo Apr 05 '19 at 13:21
  • Supeeeer, I was really curious what should be problem. – jezrael Apr 05 '19 at 13:23
  • 1
    I must have just been doing something very wrong and fixed it without noticing – wfgeo Apr 05 '19 at 13:24

0 Answers0