I have this DataFrame
and want only the records whose EPS
column is not NaN
:
>>> df
STK_ID
Simplest of all solutions:
filtered_df = df[df['EPS'].notnull()]
The above solution is way better than using np.isfinite()
Another version:
df[~df['EPS'].isna()]
You can use this:
df.dropna(subset=['EPS'], how='all', inplace=True)
It may be added at that '&' can be used to add additional conditions e.g.
df = df[(df.EPS > 2.0) & (df.EPS <4.0)]
Notice that when evaluating the statements, pandas needs parenthesis.
Don't drop, just take the rows where EPS is not NA:
df = df[df['EPS'].notna()]
I know this has already been answered, but just for the sake of a purely pandas solution to this specific question as opposed to the general description from Aman (which was wonderful) and in case anyone else happens upon this:
import pandas as pd
df = df[pd.notnull(df['EPS'])]