Search code examples
pandasin-place

pandas rename_axis not taking inplace argument


I have the following code. I thought df should have index name of INDEX at the end, given I set the inplace argument. But that's not the case. What am I missing? Or is it a bug in Pandas?

>>> df = pd.DataFrame([[1,2],[3,4]])
>>> df
   0  1
0  1  2
1  3  4
>>> df.rename_axis('INDEX', inplace=True)
       0  1
INDEX
0      1  2
1      3  4
>>> df
   0  1
0  1  2
1  3  4
>>>

Solution

  • It should be straightforward. I tried it myself and experienced the same issue, so, congratulation, you've found a bug in Pandas. Here is what you can do with your code for now:

    >>> df = df.rename_axis('INDEX')
           0  1
    INDEX
    0      1  2
    1      3  4
    >>> df
           0  1
    INDEX
    0      1  2
    1      3  4
    >>>
    

    In case you're interested to contribute to Pandas: https://pandas.pydata.org/pandas-docs/stable/contributing.html#bug-reports-and-enhancement-requests