code: def expand_counts(df, column, values=None):
      
      d = counts_to_dicts(df, column)
      if len(d) > 0:
          if values is None:
              values = set(np.concatenate(d.apply(lambda c: c.keys()).values))
          for value in values:
              name = values[value] if type(values) is dict else str(value)
              df[column + '_' + name.replace(' ', '_')] =\
                  d.apply(lambda c: c[value] if value in c else 0)
      df.drop(column, axis=1, inplace=True)
docs: expand a column containing value:count dictionaries