'Specifying astype() for reading columns of a dataframe

There is a dataframe with two columns where the first is an integer number and the second is a float number:

       inst    weight
0    126400  0.845194
1   4382592  0.083728

If I use row = df.iloc[0].astype(float) then the first column is also converted to float. I would like to statically specify int and float and assign them to variables, e.g.:

w = df['weight'].iloc[0].astype(float)
i = df['inst'].iloc[0].astype(int)

But that results in an error like AttributeError: 'float' object has no attribute 'astype'. How can I fix that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source