expanding on Drop rows with all zeros in pandas data frame, how would I edit that solution to remove all rows from a data frame that contain only 0 and NAs.
I tried:
df.loc[~(df == 0 | df.isnan()).all(axis=1))]
but got ValueError: The truth value of a Series is ambiguous.
EDIT
df[(~(df == 0 | df.isna())).all(axis=1)]
works for one of my dataframes but not the following:
df = pd.DataFrame({'x': {'Total': -3.637978807091713e-09}, 'y': {'Total': -3.637978807091713e-09}, 'z': {'Total': -3.637978807091713e-09}, 'a': {'Total': 0.0}, 'b': {'Total': 1387241.5974624965}, 'c': {'Total': 1387241.5974624965}})
When I run df[(~(df == 0 | df.isna())).all(axis=1)]
, I get an empty dataframe when the row should not be dropped because there exists a value that is not equal to either 0 or NA
.