Column names not changing

Screen Link:

My Code:

star_wars[star_wars.columns[9:15]] = star_wars[star_wars.columns[9:15]].astype(float)

episodes = ['episode_'+ str(i) for i in range(1, 7)]
ep_dict = {}
cols_to_change = star_wars.columns[9:15]

for i in range(6):
    key = cols_to_change[i]
    value = episodes[i]
    ep_dict[key] = value


What I expected to happen:
Column names to be ‘episode_1’, ‘episode_2’…, ‘episode_6’.

What actually happened:
Column names are unchanged.

There was no output error. 

Hi idris.mohamed.islam

You’ve renamed the columns with ep_dict dictionary, but haven’t saved the changes to star_wars dataframe.

You’ll have to assign the changes back to the dataframe.
star_wars = star_wars.rename(columns=ep_dict)


1 Like

Thank you! I feel silly now for not picking that up. :sweat_smile: