I have a DataFrame that I need to modify based on one of column values. In particular, when the value in column a is above 110, I want the column b to be assigned value of -99. The only issue is that first 3 rows of the dataframe contain a mix of string and numerical data types so when I try:
df.loc[df['a'] >= 110, 'b'] = -99
I get a TypeError because comparison between str and int is not allowed.
So my question is: how do I do this assignment while ignoring the first 3 rows of the dataframe?
So far I came up with this rather dodgy way:
try:
df.loc[df['a'] >= 110, 'b'] = -99
except TypeError:
pass
This does seem to work, but it obviously doesn't seem like the proper way to do it.
EDIT: And also this method just skips first 3 rows, but I really need to keep them as is.