Instead of doing :
for col in df.columns :
df[col]= df[col].astype('category')
Am doing this :
dtype0= {'brand': np.dtype('int64'),
'category': np.dtype('int64'),
'chain': np.dtype('int64'),
'company': np.dtype('int64'),
'date': np.dtype('O'),
'dept': pandas.types.dtypes.CategoricalDtype,
'id': np.dtype('int64')}
df= df.astype(dtype0)
However, it does not work. Just wondering, how to change into category using the dictionnary.
Previous answer is not correct. We can cast after creating the dataframe.
Solution is (for the record for other people stuck here): Pandas 0.19.1
dtype0= {'brand': 'int64',
'category': 'int64',
'chain': 'int64',
'company': 'int64',
'date': 'str',
'dept': 'category',
'id': 'int64'}
df= df.astype(dtype0)
casting works here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With