-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix the docstring of xs in pandas/core/generic.py #22892 #23913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d0fadf3
5ed3302
841a3cb
47e0fe2
5e39bfc
3f11180
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3270,23 +3270,40 @@ class max_speed | |||||
|
||||||
def xs(self, key, axis=0, level=None, drop_level=True): | ||||||
""" | ||||||
Returns a cross-section (row(s) or column(s)) from the | ||||||
Series/DataFrame. Defaults to cross-section on the rows (axis=0). | ||||||
Return cross-section from the Series/DataFrame. | ||||||
|
||||||
Returns a cross-section (row(s) or column(s)) | ||||||
from the Series/DataFrame. | ||||||
Defaults to cross-section on the rows (axis=0). | ||||||
|
||||||
Parameters | ||||||
---------- | ||||||
key : object | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you rename |
||||||
Some label contained in the index, or partially in a MultiIndex | ||||||
Some label contained in the index, or partially in a MultiIndex. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think more than one level can be provided, right? Can you make it clear here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure to understand this one, do you want me to precise the key ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can do |
||||||
axis : int, default 0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you do a grep of |
||||||
Axis to retrieve cross-section on | ||||||
Axis to retrieve cross-section on. | ||||||
level : object, defaults to first n levels (n=1 or len(key)) | ||||||
In case of a key partially contained in a MultiIndex, indicate | ||||||
which levels are used. Levels can be referred by label or position. | ||||||
drop_level : boolean, default True | ||||||
drop_level : bool, default True | ||||||
If False, returns object with same levels as self. | ||||||
|
||||||
Returns | ||||||
------- | ||||||
xs : Series or DataFrame | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We don't name the output anymore, just say the type. But in the next line we should have a short description on what's returned. |
||||||
|
||||||
Notes | ||||||
----- | ||||||
xs is only for getting, not setting values. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
MultiIndex Slicers is a generic way to get/set values on any level or | ||||||
levels. It is a superset of xs functionality, see | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
:ref:`MultiIndex Slicers <advanced.mi_slicers>` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Examples | ||||||
datapythonista marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
-------- | ||||||
>>> d = {'A': [4, 4, 9], 'B': [5, 0, 7], 'C': [2, 9, 3]} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's be nice to use a more real-world example. I think it makes things more complicated that the values used are arbitrary. We've been using examples with animals, so for example |
||||||
>>> df = pd.DataFrame(data=d, index=['a', 'b', 'c']) | ||||||
>>> df | ||||||
A B C | ||||||
a 4 5 2 | ||||||
|
@@ -3296,13 +3313,21 @@ def xs(self, key, axis=0, level=None, drop_level=True): | |||||
A 4 | ||||||
B 5 | ||||||
C 2 | ||||||
Name: a | ||||||
Name: a, dtype: int64 | ||||||
>>> df.xs('C', axis=1) | ||||||
a 2 | ||||||
b 9 | ||||||
c 3 | ||||||
Name: C | ||||||
|
||||||
Name: C, dtype: int64 | ||||||
>>> d = {'A': [4, 7, 6, 5], | ||||||
... 'B': [1, 5, 6, 3], | ||||||
... 'C': [8, 5, 8, 5], | ||||||
... 'D': [9, 0, 0, 3], | ||||||
... 'first': ['bar', 'bar', 'baz', 'baz'], | ||||||
... 'second': ['one', 'two', 'one', 'three'], | ||||||
... 'third': [1, 1, 1, 2]} | ||||||
>>> df = pd.DataFrame(data=d) | ||||||
>>> df = df.set_index(['first', 'second', 'third']) | ||||||
>>> df | ||||||
A B C D | ||||||
first second third | ||||||
|
@@ -3323,18 +3348,6 @@ def xs(self, key, axis=0, level=None, drop_level=True): | |||||
A B C D | ||||||
second | ||||||
three 5 3 5 3 | ||||||
|
||||||
Returns | ||||||
------- | ||||||
xs : Series or DataFrame | ||||||
|
||||||
Notes | ||||||
----- | ||||||
xs is only for getting, not setting values. | ||||||
|
||||||
MultiIndex Slicers is a generic way to get/set values on any level or | ||||||
levels. It is a superset of xs functionality, see | ||||||
:ref:`MultiIndex Slicers <advanced.mi_slicers>` | ||||||
""" | ||||||
axis = self._get_axis_number(axis) | ||||||
labels = self._get_axis(axis) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit repetitive of the short summary. Can you try to explain in an easier way what the method does. I don't think a person who hasn't used it can understand by just reading the description.