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