Why doesn\'t df.index.map(dict) work like df[\'column_name\'].map(dict)?
Here\'s a little example of trying to use index.map:
As of pandas version 0.23.x (released at May 15th, 2018) this problem is fixed:
import pandas as pd
pd.__version__ # 0.23.4
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
# one
# A 10
# B 20
# C 30
# D 40
# E 50
df.index.map(map_dict)
# one
# every 10
# good 20
# boy 30
# does 40
# fine 50
From the What's New page for pandas 0.23.0 it says:
Index.map() can now accept Series and dictionary input objects (GH12756, GH18482, GH18509).
For more information, check the help page of Index.map