Pandas dropna: The best way to remove NaN values from a series

Pandas dropna: The best way to remove NaN values from a series

Coming to Python Pandas from NumPy? You’ll reach for np.isnan:

s = Series([10, np.nan, 30])
s.loc[ ~np.isnan(s) ] # returns 10, 30

Unfortunately, this works. Better, use s.isna (or s.isnull).

But the best way to drop NaN? Use dropna:

s.dropna()  # returns 10, 30