To convert data in a dataframe column from object type to float type in Python using pandas, you can use the astype()
function. Here's an example:
main.py251 chars11 lines
Output:
main.py33 chars3 lines
In this example, we first create a sample dataframe with a column named 'Column1' containing string values. We then use the astype()
function to convert the values in the 'Column1' column from object type to float type. Finally, we check the data types of the columns to verify the conversion.
gistlibby LogSnag