簡體   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