I have this DataFrame
and want only the records whose EPS
column is not NaN
:
JavaScript
x
10
10
1
>>> df
2
STK_ID EPS cash
3
STK_ID RPT_Date
4
601166 20111231 601166 NaN NaN
5
600036 20111231 600036 NaN 12
6
600016 20111231 600016 4.3 NaN
7
601009 20111231 601009 NaN NaN
8
601939 20111231 601939 2.5 NaN
9
000001 20111231 000001 NaN NaN
10
…i.e. something like df.drop(....)
to get this resulting dataframe:
JavaScript
1
5
1
STK_ID EPS cash
2
STK_ID RPT_Date
3
600016 20111231 600016 4.3 NaN
4
601939 20111231 601939 2.5 NaN
5
How do I do that?
Advertisement
Answer
Don’t drop, just take the rows where EPS is not NA:
JavaScript
1
2
1
df = df[df['EPS'].notna()]
2