Return reshaped DataFrame organized by given index / column values. Reshape data (produce a "pivot" table) based on column values. Uses unique values from specified `index` / `columns` to form axes of the resulting DataFrame. This function does not support data aggregation, mul
(
data: DataFrame,
*,
columns: IndexLabel,
index: IndexLabel | lib.NoDefault = lib.no_default,
values: IndexLabel | lib.NoDefault = lib.no_default,
)
| 698 | |
| 699 | @set_module("pandas") |
| 700 | def pivot( |
| 701 | data: DataFrame, |
| 702 | *, |
| 703 | columns: IndexLabel, |
| 704 | index: IndexLabel | lib.NoDefault = lib.no_default, |
| 705 | values: IndexLabel | lib.NoDefault = lib.no_default, |
| 706 | ) -> DataFrame: |
| 707 | """ |
| 708 | Return reshaped DataFrame organized by given index / column values. |
| 709 | |
| 710 | Reshape data (produce a "pivot" table) based on column values. Uses |
| 711 | unique values from specified `index` / `columns` to form axes of the |
| 712 | resulting DataFrame. This function does not support data |
| 713 | aggregation, multiple values will result in a MultiIndex in the |
| 714 | columns. See the :ref:`User Guide <reshaping>` for more on reshaping. |
| 715 | |
| 716 | Parameters |
| 717 | ---------- |
| 718 | data : DataFrame |
| 719 | Input pandas DataFrame object. |
| 720 | columns : Hashable or a sequence of the previous |
| 721 | Column to use to make new frame's columns. |
| 722 | index : Hashable or a sequence of the previous, optional |
| 723 | Column to use to make new frame's index. If not given, uses existing index. |
| 724 | values : Hashable or a sequence of the previous, optional |
| 725 | Column(s) to use for populating new frame's values. If not |
| 726 | specified, all remaining columns will be used and the result will |
| 727 | have hierarchically indexed columns. |
| 728 | |
| 729 | Returns |
| 730 | ------- |
| 731 | DataFrame |
| 732 | Returns reshaped DataFrame. |
| 733 | |
| 734 | Raises |
| 735 | ------ |
| 736 | ValueError: |
| 737 | When there are any `index`, `columns` combinations with multiple |
| 738 | values. `DataFrame.pivot_table` when you need to aggregate. |
| 739 | |
| 740 | See Also |
| 741 | -------- |
| 742 | DataFrame.pivot_table : Generalization of pivot that can handle |
| 743 | duplicate values for one index/column pair. |
| 744 | DataFrame.unstack : Pivot based on the index values instead of a |
| 745 | column. |
| 746 | wide_to_long : Wide panel to long format. Less flexible but more |
| 747 | user-friendly than melt. |
| 748 | |
| 749 | Notes |
| 750 | ----- |
| 751 | For finer-tuned control, see hierarchical indexing documentation along |
| 752 | with the related stack/unstack methods. |
| 753 | |
| 754 | Reference :ref:`the user guide <reshaping.pivot>` for more examples. |
| 755 | |
| 756 | Examples |
| 757 | -------- |
no test coverage detected