Pandas DataFrame: xs() function
DataFrame - xs() function
The xs() function is used to get cross-section from the Series/DataFrame.
Syntax:DataFrame.xs(self, key, axis=0, level=None, drop_level=True)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
key | Label contained in the index, or partially in a MultiIndex. |
label or tuple of label | Required |
axis | Axis to retrieve cross-section on. |
{0 or ‘index’, 1 or ‘columns’} Default Value: 0 |
Required |
level | Whether to perform the operation in place on the data. | bool Default Value: False |
Required |
axis | Alignment axis if needed. | int Default Value: None |
Required |
level | In case of a key partially contained in a MultiIndex, indicate which levels are used. Levels can be referred by label or position. | object Defaults to first n levels (n=1 or len(key)) |
Required |
drop_level | If False, returns object with same levels as self. | bool Default Value: True |
Required |
Returns: Series or DataFrame
Cross-section from the original Series or DataFrame corresponding to the selected index levels.
Notes:
xs can not be used to set values.
MultiIndex Slicers is a generic way to get/set values on any level or levels.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - tail() function
Next: DataFrame - isin() 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