Consider the dataframe with the following columns
>>> df.columns
Index(['foo', 'bar', 'baz', 'twobaz', 'threebaz'], dtype='object', name='col')
Now, suppose you wish to replace the string baz with the string BAZ in only the last two columns, in order to do that one possible approach would be to select the last two columns then replace the string in those columns and combine them back with the remaining columns
df.columns = [*df.columns[:3], *df.columns[3:].str.replace('baz', 'BAZ', regex=True)]
>>> df.columns
Index(['foo', 'bar', 'baz', 'twoBAZ', 'threeBAZ'], dtype='object')
Another possible approach would be to use the rename method of the dataframe, the benefit of using the rename method is that it preserves the index name (if any)
c = df.columns[3:]
df = df.rename(columns=dict(zip(c, c.str.replace('baz', 'BAZ', regex=True))))
>>> df.columns
Index(['foo', 'bar', 'baz', 'twoBAZ', 'threeBAZ'], dtype='object', name='col')