繁体   English   中英

匹配字符串的索引查找位置

[英]Index find position for matching string

考虑以下示例

index_abcd = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
data = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
df = pd.DataFrame(data, index=index_abcd)
index_id= df.index

我想在索引“ index_id”中找到“ a”的位置。 我怎么做。

index_id.index('a')

不起作用(错误的“索引”对象没有属性“索引”)。 非常感谢

尝试这个:

index = pd.Index(list(df))
print index.get_loc('a')

我建议您输入:

index_id.get_loc("a")

如果我对您的理解正确,则可能是您想要的:

print(df.ix['a'].index.tolist())

输出:

[0]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM