Access index in pandas.Series.apply

前端 未结 6 1019
Happy的楠姐
Happy的楠姐 2020-11-30 02:21

Lets say I have a MultiIndex Series s:

>>> s
     values
a b
1 2  0.1 
3 6  0.3
4 4  0.7

and I want to apply a functi

6条回答
  •  北海茫月
    2020-11-30 02:54

    Convert to DataFrame and apply along row. You can access the index as x.name. x is also a Series now with 1 value

    s.to_frame(0).apply(f, axis=1)[0]
    

提交回复
热议问题