code: def train_cats(df):
      
      for n,c in df.items():
          if is_string_dtype(c): df[n] = c.astype('category').cat.as_ordered()
docs: Change any columns of strings in a panda's dataframe to a column of
      categorical values. This applies the changes inplace.
      Parameters:
      -----------
      df: A pandas dataframe. Any columns of strings will be changed to
          categorical values.
      Examples:
      ---------
      >>> df = pd.DataFrame({'col1' : [1, 2, 3], 'col2' : ['a', 'b', 'a']})
      >>> df
         col1 col2
      0     1    a
      1     2    b
      2     3    a
      note the type of col2 is string
      >>> train_cats(df)
      >>> df
         col1 col2
      0     1    a
      1     2    b
      2     3    a
      now the type of col2 is category