I often use this kind of line which create or replace a column and assign a value according to a condition:
df.loc[df['somecolumn'].str.endswith('_s'), 'somecolumn'] = '_sp'
I would like to do the same thing, but for the index column. My specific question is how do I refer to the index column?
df.loc[df.index.str.endswith('_s'), 'index column name?'] = '_sp'
I tried using df.index.name, but it creates a new column instead of changing the values within the index column.