Josh Josh - 5 months ago 30
Python Question

Keep finite entries only in Pandas

In Pandas, I can use

df.dropna()
to drop any
NaN
entries. Is there anything similar in Pandas to drop non-finite (e.g.
Inf
) entries?

Answer

You can use:

with pd.option_context('mode.use_inf_as_null', True):
   df = df.dropna()
Comments