python - TypeError: unorderable types: str() > float()

后端 未结 1 930
Happy的楠姐
Happy的楠姐 2021-01-04 09:04

i have a csv file and has v3 column but that column has some \'nan\' rows. How can i except the rows.

 dataset = pd.read_csv(\'mypath\') 

    enc = LabelEnc         


        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 09:44

    Mask the nan values by using ~isnull():

    mask = ~dataset['v3'].isnull()
    dataset['v3'][mask] = enc.fit_transform(dataset['v3'][mask])
    

    Another way is to use the pandas.factorize function, which takes care of the nans automatically (assigns them -1):

    dataset['v3'] = dataset['v3'].factorize()[0]
    

    0 讨论(0)
提交回复
热议问题