![](/img/trans.png)
[英]How do I find the value of an index in an ndarray and convert to pandas Dataframe?
[英]How do I find the index of a known value in a pandas dataframe column?
使用 describe() 函數,我注意到最大值,在本例中為 1350,它出現在我的列“LOCALGBUSED”中,但由於我的數據框包含數百萬行,我如何找到保存該值的索引?
count 3483638.000000
mean 149.145475
std 206.053277
min 0.000000
25% 6.000000
50% 80.000000
75% 200.000000
max 1350.000000
Name: LOCALGBUSED, dtype: object
我嘗試使用此代碼獲取該列的最大值的索引而不是值本身,但它顯示的索引不包含列出的最大值 1350
column = data['LOCALGBUSED']
max_index = column.idxmax()
print(max_index)
index # from code above
print(data.iloc[397386])
idxmax
返回索引,所以你需要loc
,而不是iloc
:
data.loc[data['LOCALGBUSED'].idxmax()]
.iloc
應該只使用.idxmax()
和.loc
:
data.loc[data['LOCALGBUSED'].idxmax()]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.