code: def unpivot_frame(frame, x=None, y=None,
                    var_name='variable', value_name='value'):
      
      if x is None:
          cols = frame.columns
          frame = frame.reset_index()
          x = (set(frame.columns) - set(cols)).pop()
      # frame.melt doesn't properly check for nonexisting columns, so we
      # start by indexing here. Tuples of column names also need to be
      # converted to lists for checking indexing
      if isinstance(x, tuple):
          x = list(x)
      if isinstance(y, tuple):
          y = list(y)
      if x is not None:
          _ = frame[x] # noqa
      if y is not None:
          _ = frame[y] # noqa
      return frame.melt(id_vars=x, value_vars=y,
                        var_name=var_name, value_name=value_name)
docs: Unpivot a dataframe for use with Vega/Vega-Lite
  
      The input is a frame with any number of columns,
      output is a frame with three columns: x value, y values,
      and variable names.