程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How does pandas get the row number of an element, that is, the index value

編輯:Python

It has been bothering me for a long time . Is how to get a data table , Index of values that meet certain conditions , Or line number .

Today we can finally do it .

such as :

There's a data ,

To find this data , yes 2018 What about the year? , What do I do , Can write for loop , It's all written like this :

for i in range(df.shape[0]):
if df.iloc[i, ]['year'] == 2018:
print(i)
print(df.iloc[i, ]['year'])
break

It has to be written here , Need to use i As a counter . Can not be written in other styles for loop , Found today , You can also write .

for x in df['year']:
if x == 2018:
print(x)
print(list(df['year']).index(x))
break

Here's one index function , The flight coordinates will be output , however , It has always been an iterative object , Not a specific value . Use list, Display this value directly . That's good . Conform to common habits . Don't rely on i As a counter


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved