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.