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?
By using replace() & dropna() methods you can remove infinite values from rows & columns in pandas DataFrame. Infinite values are represented in NumPy as np. inf & -np. inf for negative values.
The order of elements in a pandas Series (i.e., a column in a pandas DataFrame) will not change unless you do something that makes it change. And the order of a python list is guaranteed to reflect insertion order (SO thread). So yes, df[0].
You can use:
with pd.option_context('mode.use_inf_as_null', True):
df = df.dropna()
df[np.isfinite(df) | np.isnan(df)]
You can use .dropna()
after a DF[DF==np.inf]=np.nan
, (unless you still want to keep the NAN
s and only drop the inf
s)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With