Map dataframe index using dictionary

I’m not answering your question… Just giving you a better work around.
Use to_series() them map

df = pd.DataFrame({'one': {'A': 10, 'B': 20, 'C': 30, 'D': 40, 'E': 50}})
map_dict = {'A': 'every', 'B': 'good', 'C': 'boy', 'D': 'does', 'E': 'fine'}

df['two'] = df.index.to_series().map(map_dict)

df

   one    two
A   10  every
B   20   good
C   30    boy
D   40   does
E   50   fine

Leave a Comment