Reason your code doesn't work:
Indexes are not mutable, they're Index objects, so you would have to modify all columns altogether. It doesn't support slice assignment.
Just the same as tuples, tuples are also mutable therefore tuples also don't support slicing assignment.
As you can see:
>>> a = (1, 2, 3)
>>> a[:2] = (100, 200)
Traceback (most recent call last):
File "<pyshell#106>", line 1, in <module>
a[:2] = (100, 200)
TypeError: 'tuple' object does not support item assignment
>>>
Would also give an error.
Solutions:
Something like:
df.columns = np.concatenate([df.columns[:-2], df.columns[-2:] + 'Ind_'])
Or:
df = df.rename(columns = lambda x: f"{x}Ind_" if x in {'D', 'E'} else x)
Or:
df = df.set_axis(np.concatenate([df.columns[:-2], df.columns[-2:] + 'Ind_']), axis=1)
Or this way with concat:
df = pd.concat([df.iloc[:, :-2], df.iloc[:, -2:].add_suffix('Ind_')], axis=1)
Also this way with join:
df = df.iloc[:, :-2].join(df.iloc[:, -2:].add_suffix('Ind_'))
df.rename(columns = lambda col: f"Ind_{col}" if col in ('D', 'E') else col)or do an assignment to the columns :df.columns = [f"Ind_{col}" if col in ('D', 'E') else col for col in df]. Indexes are not mutable, so you have to create a new index altogether.