change dataframe column type 1

change dataframe column type

# You can use "astype" method
# suppose you want to correct your "sales" column data type
df['sales'] = df['sales'].astype('float64')

Here is what the above code is Doing:
1. We are using the “astype” method to change the data type of the “sales” column from “object” to “float64”.
2. We are assigning the output of the “astype” method to the “sales” column itself.

Similar Posts