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?
-
Possible duplicate of dropping infinite values from dataframes in pandas?chepyle– chepyle2018-06-07 21:36:35 +00:00Commented Jun 7, 2018 at 21:36
Add a comment
|
4 Answers
You can use:
with pd.option_context('mode.use_inf_as_null', True):
df = df.dropna()
4 Comments
3pitt
this causes my dataframe to go from 130 rows to 0. The na/inf issue I'm investigating is a column of all blanks, i believe
Ayrton Bourn
You can specify the axis you wish to drop NaNs over as a parameter to dropna
mwaskom
This will be deprecated in pandas as of 2.1.0.
Marco Spinaci
As @mwaskom said, this option has now been renamed to mode.use_inf_as_na
You can use .dropna() after a DF[DF==np.inf]=np.nan, (unless you still want to keep the NANs and only drop the infs)