Pandas DataFrame: pivot() function
DataFrame - pivot() function
The pivot() function is used to reshaped a given DataFrame organized by given index / column values. This function does not support data aggregation, multiple values will result in a MultiIndex in the columns.
Syntax:
DataFrame.pivot(self, index=None, columns=None, values=None)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
index | Column to use to make new frame’s index. If None, uses existing index. | string or object | Optional |
columns | Column to use to make new frame’s columns. | string or object | Required |
values | Column(s) to use for populating new frame’s values. If not specified, all remaining columns will be used and the result will have hierarchically indexed columns. | string, object or a list of the previous | Optional |
Returns: DataFrame
Returns reshaped DataFrame.
Raises: ValueError- When there are any index, columns combinations with multiple values. DataFrame.pivot_table when you need to aggregate.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - droplevel() function
Next: DataFrame - pivot_table() function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework