Remove NaN from pandas series

前端 未结 3 1434
抹茶落季
抹茶落季 2020-11-29 05:05

Is there a way to remove a NaN values from a panda series? I have a series that may or may not have some NaN values in it, and I\'d like to return a copy of the series with

3条回答
  •  隐瞒了意图╮
    2020-11-29 05:31

    >>> s = pd.Series([1,2,3,4,np.NaN,5,np.NaN])
    >>> s[~s.isnull()]
    0    1
    1    2
    2    3
    3    4
    5    5
    

    update or even better approach as @DSM suggested in comments, using pandas.Series.dropna():

    >>> s.dropna()
    0    1
    1    2
    2    3
    3    4
    5    5
    

提交回复
热议问题