Search code examples
pythonpandasdata-cleaning

Data Wrangling in python exclude entries with '0' values


I have a pandas data frame that contains 2 columns W(number of Wins) and L(number of Losses). I would like to eliminate all rows of data that have a value of 0 for both W and L.

pitching_df.groupby('playerID')['W', 'L'].sum()

playerID    W   L
aardsda01   2   5
aasedo01    3   8
abbotpa01   0   0
abernte02   8   19

Solution

  • You can try

    df[df[['W', 'L']].ne(0).all(1)]
    
    
    playerID        W   L
    0   aardsda01   2   5
    1   aasedo01    3   8
    3   abernte02   8   19