I am comparing two columns in a pandas DF, A and B like this:
df['A'].gt(df['B'])
but get this error:
TypeError: '>' not supported between instances of 'str' and 'int'
when I lookup the dtypes: df.dtypes
I see this output:
id: object
A: object
B: int64
when I look at 5 top records with do df.head()
I see this:
id A B
a1 2 2.353566677998
a2 4 4.454444231211
a3 3 6.777888665343
.....
how to solve this error:
TypeError: '>' not supported between instances of 'str' and 'int'
when doing this comparison:
df['A'].gt(df['B'])
Looks like many people are asking this but I couldn't find one that matches my issue!
df['A'] = pd.to_numeric(df['A'], errors='coerce')before comparison?