def unpivot_frame(frame, x=None, y=None,<EOL>var_name='<STR_LIT>', value_name='<STR_LIT:value>'):
if x is None:<EOL><INDENT>cols = frame.columns<EOL>frame = frame.reset_index()<EOL>x = (set(frame.columns) - set(cols)).pop()<EOL><DEDENT>if isinstance(x, tuple):<EOL><INDENT>x = list(x)<EOL><DEDENT>if isinstance(y, tuple):<EOL><INDENT>y = list(y)<EOL><DEDENT>if x is not None:<EOL><INDENT>_ = frame[x] <EOL><DEDENT>if y is not None:<EOL><INDENT>_ = frame[y] <EOL><DEDENT>return frame.melt(id_vars=x, value_vars=y,<EOL>var_name=var_name, value_name=value_name)<EOL>
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.