To convert a column in a pandas DataFrame from int data type to float, you can use the astype
method. Here's an example:
main.py235 chars11 lines
This will output:
main.py112 chars5 lines
In the example above, the astype(float)
method is used to convert the 'int_column' from int data type to float data type. The converted column is then assigned to a new column 'float_column' in the DataFrame.
Note that the original 'int_column' is still present in the DataFrame, and the converted values are stored in the 'float_column'.
gistlibby LogSnag