定位非数字索引值的数字位置 [英] locate the numeric position of a non numeric index value

查看:48
本文介绍了定位非数字索引值的数字位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下系列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'

这可以做到,但是我认为我们都可以同意这是很糟糕的:

This will do it, but I think we can all agree this is gross:

s.reset_index().index.to_series()[s.reset_index().iloc[:, 0] == 'D'].iloc[0]

推荐答案

您可以使用

You can use Index.get_loc:

print(s.index.get_loc('D'))
3

这篇关于定位非数字索引值的数字位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆