我认为无法
apply访问该索引;它将每行视为一个numpy对象,而不是一个Series,如您所见:
In [27]: s.apply(lambda x: type(x))Out[27]: a b1 2 <type 'numpy.float64'>3 6 <type 'numpy.float64'>4 4 <type 'numpy.float64'>
要解决此限制,请将索引提升为列,应用函数,然后使用原始索引重新创建Series。
Series(s.reset_index().apply(f, axis=1).values, index=s.index)
可能使用其他方法
s.get_level_values,在我看来,这通常很难看,或者
s.iterrows()可能更慢-可能取决于具体
f操作。



