cats = ['A', 'B', 'C', 'D', 'E']
int_matrix = np.random.randint(10, size=(7, 5))
df = pd.DataFrame(data=int_matrix, columns=cats)
print('Original example data\n')
print(df)
print(df.dtypes)
col_names = list(df)
print("""
Names of dataframe columns""")
print(col_names)
for col in col_names:
    df[col] = df[col].astype('category', copy=False)
print("""
Example data changed to category type""")
print(df)
print(df.dtypes)
how to convert all columns from numeric to categorical using Python