I have this table where one of the column has string and integer, and I want to convert the string to integer as 0. How can I do this in python? The column similar like this:
size
1
1
1
2
ABC
I expect it can be converted as:
size
1
1
1
2
0
Use to_numeric with errors='coerce' for missing values instead strings, replace them by Series.fillna and last convert to integers:
df['size'] = pd.to_numeric(df['size'], errors='coerce').fillna(0).astype(int)
print (df)
size
0 1
1 1
2 1
3 2
4 0