简体   繁体   English

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

[英]Index find position for matching string

Consider following example 考虑以下示例

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

I want to find the position of 'a' in the index "index_id". 我想在索引“ index_id”中找到“ a”的位置。 How do I do that. 我怎么做。 Trying

index_id.index('a')

does not work (error 'Index' object has no attribute 'index'). 不起作用(错误的“索引”对象没有属性“索引”)。 Thanks a lot 非常感谢

Try this: 尝试这个:

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

我建议您输入:

index_id.get_loc("a")

If I understand you correctly, this may be what you want: 如果我对您的理解正确,则可能是您想要的:

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

Output: 输出:

[0]

暂无
暂无

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

相关问题 查找字符串中字符的索引位置 - Find index position of characters in string 在字符串中查找匹配的左/右大括号索引 - Find the matching opening/closing brace index in a string Pythonic方法找到匹配负正则表达式的字符串中的最后位置 - Pythonic way to find the last position in a string matching a negative regex Python - 查找字符串中第一次出现的字符串列表的索引位置 - Python - find index position of first occurrence of a list of strings within a string Python:使用index / find在HTML中搜索Unicode字符串会返回错误的位置 - Python: Searching for Unicode string in HTML with index/find returns wrong position 从 numpy 中的测试数组中找到具有匹配值的数组中所有元素的索引 position - Find the index position of all elements within an array with matching values from a test array in numpy 找到匹配的字符串,然后+ 1到元素 - Find a matching string and then + 1 to element 查找第一个匹配 substring 的索引 - Find index of first matching substring 根据标签列表中该单词的索引位置,查找字符串中单词的开始和结束位置 - Find the start and end position of a word in a string based on the index position of that word from a label list 编写一个递归函数matching_bracket(string, idx) 来查找与string[idx] 处的左括号匹配的右括号的索引 - Write a recursive function matching_bracket(string, idx) to find the index of the close bracket matching the open bracket at string[idx]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM