Week 10 (Querying from dataframe)

In Week 10 of the Data Science Foundations Course , in the video of ‘ Querying from dataframe ’ a solution was provided regarding queries in the planetary data set to filter the dataset according to certain conditions.

The Question was :

Filter and show only those rows which have planets that are found in the 2010s and method is ‘Radial Velocity’ and ‘Transit’ and distance is large (>75 percentile).

Two methods were taught. In the first method of FOR LOOP , using the for loop but the result didn’t match my results which I tried to cross-check through describe command for data frames , the taught code and what I coded was :

df_ = df.copy()

per_75 = df_.distance.quantile(0.75)

for i,r in df_.iterrows():

if r[‘year’] < 2010:



if r[‘method’] != ‘Radial Velocity’ and r[‘method’] != ‘Transit’:



if r[‘distance’] < per_75:



The result in the tutorial after df_.describe() was 50 rows × 6 columns while my code gave me 324 rows × 6 columns .

Please help me find out what could be the problem I am facing here. I have tried but am not able to get the answer similar to what was in the tutorial.

Anyone with any sort of help is welcome.


can share the o/p, please?

This is the o/p that i got

you are not filtering ‘year’

I filtered the column ‘year’ .

Please verify , I have written the code above.

Hi @ayushraj0309,

Please refer to the following line:

The operation you’re using is and, please try replacing it with or.