8000 DOC: Fixed the doctsring for _set_axis_name (GH 22895) by bkjchoi72 · Pull Request #22969 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DOC: Fixed the doctsring for _set_axis_name (GH 22895) #22969

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed the example so that it makes sense
  • Loading branch information
bkjchoi72 committed Oct 9, 2018
commit a7eb3d8121a32119f2b0974e8b1f9234d1c6206f
52 changes: 28 additions & 24 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,22 +1164,24 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False):

**DataFrame**

>>> df = pd.DataFrame({"name": ["dog", "cat", "monkey"], "legs": [4, 4, 2]})
name legs
0 dog 4
1 cat 4
2 monkey 2
>>> df = pd.DataFrame({"num_legs": [4, 4, 2],
... "num_arms": [0, 0, 2]},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indentation of this line looks wrong

... ["dog", "cat", "monkey"])
num_legs num_arms
dog 4 0
cat 4 0
monkey 2 2
>>> df.rename_axis("animal")
name legs
num_legs num_arms
animal
0 dog 4
1 cat 4
2 monkey 2
>>> df.rename_axis("id", axis="columns")
id name legs
0 dog 4
1 cat 4
2 monkey 2
dog 4 0
cat 4 0
monkey 2 2
>>> df.rename_axis("limbs", axis="columns")
limbs num_legs num_arms
dog 4 0
cat 4 0
monkey 2 2
"""
inplace = validate_bool_kwarg(inplace, 'inplace')
non_mapper = is_scalar(mapper) or (is_list_like(mapper) and not
Expand Down Expand Up @@ -1225,18 +1227,20 @@ def _set_axis_name(self, name, axis=0, inplace=False):

Examples
--------
>>> df = pd.DataFrame({"legs": [4, 4, 2]})
legs
0 4
1 4
2 2
>>> df = pd.DataFrame({"num_legs": [4, 4, 2]},
... ["dog", "cat", "monkey"])
num_legs
dog 4
cat 4
monkey 2
>>> df._set_axis_name("animal")
legs
num_legs
animal
0 4
1 2
2 0
>>> df.index = pd.MultiIndex.from_product([["mammal"], ['dog', 'cat', 'monkey']])
dog 4
cat 4
monkey 2
>>> df.index = pd.MultiIndex.from_product(
... [["mammal"], ['dog', 'cat', 'monkey']])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you try to present this using a better indentation. I think this is not pep8 compatible

>>> df._set_axis_name(["type", "name"])
legs
type name
Expand Down
0