Remove NaN from pandas series
>>> s = pd.Series([1,2,3,4,np.NaN,5,np.NaN])>>> s[~s.isnull()]0 11 22 33 45 5
update or even better approach as @DSM suggested in comments, using pandas.Series.dropna()
:
>>> s.dropna()0 11 22 33 45 5
If you have a pandas serie with NaN, and want to remove it (without loosing index):
serie = serie.dropna()
# create data for exampledata = np.array(['g', 'e', 'e', 'k', 's']) ser = pd.Series(data)ser.replace('e', np.NAN)print(ser)0 g1 NaN2 NaN3 k4 sdtype: object# the codeser = ser.dropna()print(ser)0 g3 k4 sdtype: object