>>> df.astype({'col1': 'int32'}).dtypes
col1 int32
col2 int64
dtype: object
# Individual
df['a'] = df_test['a'].astype('float64')
df['b'] = df_test['b'].astype('int64')
# Batch
dtype_d = {"a": "float64", "b": "int64"} # dtype dictio
df = df.astype(dtype_d)
df.astype(int)
df = pd.read_csv("weather.tsv", sep=" ",
dtype={'Day': str,'Wind':int64})
df.dtypes
# select columns that need to be converted
cols = df.select_dtypes(include=['float64']).columns.to_list()
df = df.astype({col:int for col in cols})
convert pandas datatype
df_asset['Dwell_Type']=df_asset['Dwell_Type'].astype('O')#here we used uppercase O to set as object.
df_asset['Zone_Class']=df_asset['Zone_Class'].astype('O')
df_asset['OverallQual']=df_asset['OverallQual'].astype('O')
df_asset['OverallCond']=df_asset['OverallCond'].astype('O')
df_asset['BsmtFullBath']=df_asset['BsmtFullBath'].astype('O')
df_asset['BsmtHalfBath']=df_asset['BsmtHalfBath'].astype('O')
df['current_anniversary_date'] = df['current_anniversary_date'].astype('datetime64[ns]')