Subset the DataFrame or Series according to the specified index labels.
For DataFrame, filter rows or columns depending on axis
argument. Note that this routine does not filter based on content. The filter is applied to the labels of the index.
Keep labels from axis which are in items.
Keep labels from axis for which âlike in label == Trueâ.
Keep labels from axis for which re.search(regex, label) == True.
The axis to filter on, expressed either as an index (int) or axis name (str). By default this is the info axis, âcolumnsâ for DataFrame
. For Series
this parameter is unused and defaults to None
.
The filtered subset of the DataFrame or Series.
See also
DataFrame.loc
Access a group of rows and columns by label(s) or a boolean array.
Notes
The items
, like
, and regex
parameters are enforced to be mutually exclusive.
axis
defaults to the info axis that is used when indexing with []
.
Examples
>>> df = pd.DataFrame( ... np.array(([1, 2, 3], [4, 5, 6])), ... index=["mouse", "rabbit"], ... columns=["one", "two", "three"], ... ) >>> df one two three mouse 1 2 3 rabbit 4 5 6
>>> # select columns by name >>> df.filter(items=["one", "three"]) one three mouse 1 3 rabbit 4 6
>>> # select columns by regular expression >>> df.filter(regex="e$", axis=1) one three mouse 1 3 rabbit 4 6
>>> # select rows containing 'bbi' >>> df.filter(like="bbi", axis=0) one two three rabbit 4 5 6
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4