LabelEncoder Error: ‘>’ not supported between instances of ‘str’ and ‘float’


Issue:

When using LabelEcoder for the column with values like “02 – ABC’, it was throwing error:

TypeError: ‘>’ not supported between instances of ‘str’ and ‘float’

Code used:

Error msg:

Solution:

Its most likely related to the definition of an object type in pandas, object type does not necessarily mean dtype str. and pandas forces the type to change when it inserts NaN values

please use .astype(str) to solve the error

Thank You

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.