code: def convert_to_categorical(df):
          
          might_be_categorical = df.select_dtypes(include=[object]).columns.tolist()
          for column in might_be_categorical:
              if df[column].nunique() < 20:
  
                  # Convert the column
                  print('Changing column {:s} to category...'.format(column))
                  df[column] = pd.Categorical(df[column])
docs: Run a heuristic on the columns of the dataframe to determine whether it contains categorical values
             if the heuristic decides it's categorical then the type of the column is changed
          Args:
              df (dataframe): The dataframe to check for categorical data