Skip to content Skip to sidebar Skip to footer

Python / Pandas: Dataframe Subset By Filter Criteria

I have the following dataframe which is list of races and results. Date R # Fin Win 0 11182017 1 1 2 0 1 11182017 1 2 1 5 2 11

Solution 1:

You can use groupby + filter

df.groupby(['Date','R']).filter(lambda x : (x['Win']>=10).any())
Out[568]: 
       Date  R  #  Fin  Win
3  11182017  2  1    2    0
4  11182017  2  2    1   10

Another solution by using transform

df[df.groupby(['Date','R']).Win.transform(lambda x : (x>=10).any())]
Out[573]: 
       Date  R  #  Fin  Win
3  11182017  2  1    2    0
4  11182017  2  2    1   10

Post a Comment for "Python / Pandas: Dataframe Subset By Filter Criteria"