Can't drop NAN with dropna in pandas

后端 未结 4 1920
心在旅途
心在旅途 2020-11-27 07:54

I import pandas as pd and run the code below and get the following result

Code:

traindataset = pd.read_csv(\'/Users/train.csv\')
print traindataset.d         


        
4条回答
  •  醉酒成梦
    2020-11-27 08:05

    pd.DataFrame.dropna uses inplace=False by default. This is the norm with most Pandas operations; exceptions do exist, e.g. update.

    Therefore, you must either assign back to your variable, or state explicitly inplace=True:

    df = df.dropna(how='any')           # assign back
    df.dropna(how='any', inplace=True)  # set inplace parameter
    

    Stylistically, the former is often preferred as it supports operator chaining, and the latter often does not yield any or significant performance benefits.

提交回复
热议问题