df = pd.DataFrame({'col1': [1, 2, 3, 4, 5], 'col2': list('abcab'), 'col3':
    list('ababb')})
df['col2'] = df['col2'].astype('category')
df['col3'] = df['col3'].astype('category')
Convert categorical data in pandas dataframe