Pandas DataFrame: unstack() function
DataFrame - unstack() function
Pivot a level of the (necessarily hierarchical) index labels, returning a DataFrame having a new level of column labels whose inner-most level consists of the pivoted index labels.
If the index is not a MultiIndex, the output will be a Series (the analogue of stack when the columns are not a MultiIndex).
Syntax:
DataFrame.unstack(self, level=-1, fill_value=None)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
level | Level(s) of index to unstack, can pass level name | int, string, or list of these(last level) Default Value: 1 |
Required |
fill_value | missing values | replace NaN with this value if the unstack produces | Required |
Returns: Series or DataFrame
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - stack() function
Next: DataFrame - melt() 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