0
d1=df.loc[(df.Age<50) & (df.Age>10)]
d2=df[(df['Age']<50) & (df['Age']>10)]
d1 == d2

the output is: enter image description here

and when i use loc and iloc to filter data, the outputs also different:

d1.loc[[100]]

enter image description here

d1.iloc[[100], :]

enter image description here

refer to this answer, Lev said locinclude the start and the stop index, so I tried this:

d1.loc[[99], :]

enter image description here

but they are also different. Why?

Can someone help me?

Alex
  • 56
  • 5

1 Answers1

0

loc filters the dataframe based on the index column. For example, when you are calling df.loc[[100]], it will return the contents of the row with index value 100. iloc filters the dataframe based on the location. df.iloc[[100]] will return 100th row of your dataframe (numbering starts from 0). If the index of 100th row is 100, then df.iloc[[100]] and df.loc[[100]] will return the same row.

MonkeyDLuffy
  • 508
  • 1
  • 5
  • 24