code: def binarize(df, category_classes, all_classes=True, drop=True,
               astype=None, inplace=True, min_freq=None):
      
      if type(category_classes) is not dict:
          columns = set(category_classes)
          category_classes = {column: df[column].unique() for column in columns}
      else:
          columns = category_classes.keys()
  
      df_new = df if inplace else df.drop(columns, axis=1)
  
      for category in columns:
          classes = category_classes[category]
          for i in range(len(classes)-1 if not all_classes else len(classes)):
              c = df[category] == classes[i]
              if not min_freq or c.sum() >= min_freq:
                  if astype is not None:
                      c = c.astype(astype)
                  df_new['%s_%s' % (category, str(classes[i]).replace(' ', '_'))] = c
  
      if drop and inplace:
          df_new.drop(columns, axis=1, inplace=True)
  
      return df_new
docs: Binarize specified categoricals. Works inplace!
  
      Args:
          - df: the DataFrame whose columns to binarize
          - category_classes: either a dict of (column : [class1, class2, ...]) pairs
              or a collection of column names, in which case classes are
              given using df[column].unique()
          - all_classes: when False, the last class is skipped
          - drop: when True, the original categorical columns are dropped
          - astype: a type for the resulting binaries, e.g. np.float32.
              When None, use the defualt (bool).
          - inplace: whether to modify the DataFrame inplace
  
      Returns:
          the DataFrame with binarized columns