Let's say I have a dataframe that looks like this...
xdf = pd.DataFrame({ 'foo': ['1', '2', '3']})
| foo | 
|---|
| 1 | 
| 2 | 
| 3 | 
And I want to convert the column to type int. I can do that easily with...
df = df.astype({ 'foo': 'int' })
But if my dataframe looks like this...
df = pd.DataFrame({ 'foo': ['1.0', '2.0', '3.0']})
| foo | 
|---|
| 1.0 | 
| 2.0 | 
| 3.0 | 
And I try to convert it from object to int then I get this error
ValueError: invalid literal for int() with base 10: '1.0'
Why doesn't this work? How would I go about converting this to an int properly?
 
     
    