I am using Pandas to analyze data from csv. The dataframe look like this:
tech_nbr door_age service_spend service_calls
0 2 -7,987 1 3
1 3 -7,987 1 3
2 231561 -7,987 1 3
3 2531885 13 1 3
4 A451349 9 1 3
Now I want to filter out all the rows with negative door_age
such as row 0 and 1 using the following command.
df_filtered = df.filter(df.door_age > 0)
However I got error:
TypeError: '>' not supported between instances of 'str' and 'int'
I guess there some values of ages are not numeric, so I added the following line to drop rows with non-numeric door_age
based on Remove non-numeric rows in one column with pandas
df[df.door_age.apply(lambda x: x.isnumeric())]
It did seem to remove a lot of rows, but I still got the same error. So I also filtered out rows with null values for door_age
using `df = df.dropna(subset=['door_age']). However it did not help either.
Why am I still getting this error?