Using a pandas dataframe, for example:
import pandas as pd
df = pd.DataFrame({'a': [1,0,0], 'b': [1,0,0]})
I have used the answer from Pandas: sum DataFrame rows for given columns to sum the two columns:
foo = df[['a', 'b']].sum(axis=1)
What I'm struggling with now is how to filter the rows that are assigned to foo
. So, for example, I only want the rows that are greater than 0 to be in the result stored in foo
. Does anyone know the best of doing this?