Answers for "dataframe astype int"

19

how to convert data type of a column in pandas

# You can use "astype" method
# suppose you want to correct your "sales" column data type
df['sales'] = df['sales'].astype('float64')
Posted by: Guest on July-20-2021
0

convert categorical data type to int in pandas

from sklearn import preprocessing

lab_encoder = preprocessing.LabelEncoder()
df['column'] = lab_encoder.fit_transform(df['column'])
Posted by: Guest on November-09-2021

Browse Popular Code Answers by Language