Map dataframe index using dictionary

后端 未结 6 1868
Happy的楠姐
Happy的楠姐 2020-12-08 20:29

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:



        
6条回答
  •  悲&欢浪女
    2020-12-08 20:59

    Adding get at the end

    df['Two']=df.index.map(map_dict.get)
    df
    Out[155]: 
       one    Two
    A   10  every
    B   20   good
    C   30    boy
    D   40   does
    E   50   fine
    

提交回复
热议问题