I have a data frame like this:
a = pd.DataFrame({'foo':[1,2,3,'str']})
foo
0 1
1 2
2 3
3 str
I want to set the data type to int64:
a['foo'].astype('int32')
but I got an error message:
ValueError: invalid literal for int() with base 10: 'str'
How to set unexpected data type to NA. In my case, I'd like to return data frame like the following:
foo
0 1
1 2
2 3
3 NA