[英]locate the numeric position of a non numeric index value
考虑系列s
如下:
s = pd.Series(np.arange(18, 0, -3), list('ABCDEF'))
s
A 18
B 15
C 12
D 9
E 6
F 3
dtype: int32
我想得到'D'
的数字位置
这样做会,但我认为我们都同意这是严重的:
s.reset_index().index.to_series()[s.reset_index().iloc[:, 0] == 'D'].iloc[0]
您可以使用Index.get_loc
:
print(s.index.get_loc('D'))
3
m = s.index == 'D'
idx = m.argmax() if m.any() else None
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.