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