pandas.DataFrame.pivot¶
- DataFrame.pivot(index=None, columns=None, values=None)¶
- Reshape data (produce a “pivot” table) based on column values. Uses unique values from index / columns to form axes and return either DataFrame or Panel, depending on whether you request a single value column (DataFrame) or all columns (Panel) - Parameters : - index : string or object - Column name to use to make new frame’s index - columns : string or object - Column name to use to make new frame’s columns - values : string or object, optional - Column name to use for populating new frame’s values - Returns : - pivoted : DataFrame - If no values column specified, will have hierarchically indexed columns - Notes - For finer-tuned control, see hierarchical indexing documentation along with the related stack/unstack methods - Examples - >>> df foo bar baz 0 one A 1. 1 one B 2. 2 one C 3. 3 two A 4. 4 two B 5. 5 two C 6. - >>> df.pivot('foo', 'bar', 'baz') A B C one 1 2 3 two 4 5 6 - >>> df.pivot('foo', 'bar')['baz'] A B C one 1 2 3 two 4 5 6