TypeError: ufunc 'invert' not supported for the input types

Viewed 3083

I am trying to drop rows in my dataframe

The column

Field:FacilityCode
mama100
mimba190
mama1
mimba67
#delete invalid code from df
df = df[~df['Field:FacilityCode'].str.len()>8] | df[~df['Field:FacilityCode'].str.len()>7]   

expected output

Field:FacilityCode
mama100
mimba190

here is the error

TypeError: ufunc 'invert' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'''

How can I fix it??

1 Answers

Because if length if greater like 7 it means is greater like 8 solution should be simplify - get all rows if length is less or equal 7:

df = df[df['Field:FacilityCode'].str.len()<=7]   

But your solution is possible:

df[~(df['Field:FacilityCode'].str.len()>8) | ~(df['Field:FacilityCode'].str.len()>7)]

EDIT: From output data condition is >7 for filter equal or higher like 7:

df = df[df['Field:FacilityCode'].str.len()>=7]

print (df)
  Field:FacilityCode
0            mama100
1           mimba190
3            mimba67
Related