We can count occurrences of nan with df.isna().count()
Is there is a similar function to count inf?
We can count occurrences of nan with df.isna().count()
Is there is a similar function to count inf?
use np.isinf()
df = pd.DataFrame({'data' : [0,0,float('inf'),float('inf')]})
print(df)
data
0 0.0
1 0.0
2 inf
3 inf
df.groupby(np.isinf(df['data'])).count()
data
data
False 2
True 2
you can use isinf() and ravel() in one line
# Pandas Series.ravel() function returns the flattened underlying data as an ndarray.
np.isinf(df["Col"]).values.ravel().sum()