def pivot(expr, rows, columns, values=None):
    """
    Produce ‘pivot’ table based on 3 columns of this DataFrame.
    Uses unique values from rows / columns and fills with values.

    :param expr: collection
    :param rows: use to make new collection's grouped rows
    :param columns: use to make new collection's columns
    :param values: values to use for populating new collection's values
    :return: collection

    :Example:

    >>> df.pivot(rows='id', columns='category')
    >>> df.pivot(rows='id', columns='category', values='sale')
    >>> df.pivot(rows=['id', 'id2'], columns='category', values='sale')
    """

    rows = [expr._get_field(r) for r in utils.to_list(rows)]
    columns = [expr._get_field(c) for c in utils.to_list(columns)]
    if values:
        values = utils.to_list(values)
    else:
        names = set(c.name for c in rows + columns)
        values = [n for n in expr.schema.names if n not in names]
        if not values:
            raise ValueError('No values found for pivot')
    values = [expr._get_field(v) for v in values]

    if len(columns) > 1:
        raise ValueError('More than one `columns` are not supported yet')

    return PivotCollectionExpr(_input=expr, _group=rows,
                               _columns=columns, _values=values)
def pivot ( expr , rows , columns , values = None ) : rows = [ expr . _get_field ( r ) for r in utils . to_list ( rows ) ] columns = [ expr . _get_field ( c ) for c in utils . to_list ( columns ) ] if values : values = utils . to_list ( values ) else : names = set ( c . name for c in rows + columns ) values = [ n for n in expr . schema . names if n not in names ] if not values : raise ValueError ( 'No values found for pivot' ) values = [ expr . _get_field ( v ) for v in values ] if len ( columns ) > 1 : raise ValueError ( 'More than one `columns` are not supported yet' ) return PivotCollectionExpr ( _input = expr , _group = rows , _columns = columns , _values = values )
Produce ‘pivot’ table based on 3 columns of this DataFrame.
    Uses unique values from rows / columns and fills with values.

    :param expr: collection
    :param rows: use to make new collection's grouped rows
    :param columns: use to make new collection's columns
    :param values: values to use for populating new collection's values
    :return: collection

    :Example:

    >>> df.pivot(rows='id', columns='category')
    >>> df.pivot(rows='id', columns='category', values='sale')
    >>> df.pivot(rows=['id', 'id2'], columns='category', values='sale')