python-TypeError:无法排序的类型:str()> float()

索拉·马斯特罗

我有一个csv文件,并具有v3列,但该列具有一些“ nan”行。除了行,我怎么能。

 dataset = pd.read_csv('mypath') 

    enc = LabelEncoder()
    enc.fit(dataset['v3'])
    print('fitting')
    dataset['v3'] = enc.transform(dataset['v3'])
    print('transforming')
    print(dataset['v3'])
    print('end')

编辑:V3列具有A,C,B,A,C,D 、、、 A,S,就像这样,我想将其转换为(1,2,3,1,2,4 ,,, 1, 7)

使用〜isnull()屏蔽nan值:

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

另一种方法是使用pandas.factorize函数,该函数自动处理nan(将它们分配为-1):

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Django / Python TypeError不可排序的类型:float()<HighscoreEasy()

排序float python列表

Python:pct_change引发TypeError:/:'str'和'float'不受支持的操作数类型

TypeError:-:'str'和'float'python pandas的不受支持的操作数类型

Python - 类型错误:无法排序的类型:str() < int()

TypeError:无法将“ float”对象隐式转换为str或TypeError:-:“ str”和“ float”的不受支持的操作数类型

groupby python TypeError:不可排序的类型:tuple()<str()

Python 3.5.0-TypeError:无法将序列乘以'float'类型的非整数

Python 3:TypeError:无法将序列乘以'float'类型的非整数

无法在Python 3.6中将str转换为float

Python TypeError:“ float”对象无法解释为整数

TypeError:'float'对象不可下标--Python

Python:TypeError:“ float”对象不可迭代

Python中的double / float类型精度

Python 3:类型错误:+ 不支持的操作数类型:'float' 和 'str'

Python 2到3错误。TypeError:不可排序的类型:int()<= str()

Python3-while ids> Stop:TypeError:不可排序的类型:str()> int()

无法在python 3中获得python 2的确切str(float)结果

TypeError:无法连接“ str”和“ float”对象:pandas

Python类型错误问题TypeError:-:'Table'和'float'不受支持的操作数类型

Python 3:不支持的操作数类型 -:'str' 和 'float'

Python3:+不支持的操作数类型:“ float”和“ str”

在对数据框进行排序时,为什么在没有NaN值的情况下为什么会出现“ TypeError:乱序类型:str()<float()”?

Python TypeError:^:'float'和'int'不支持的操作数类型

熊猫Python-TypeError:一元错误的操作数类型〜:'float'

TypeError:+ =:Python 3中不支持的操作数类型为“ float”和“ NoneType”

TypeError:无法将序列乘以'float'类型的非整数| 烧瓶

TypeError:无法将序列乘以'float'类型3.3的非整数

如何更改将float('inf')转换为str的python方式?