Skip to content

DOC: fix the pandas.DataFrame.add example #20077

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
Changes from all commits
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
18 changes: 9 additions & 9 deletions pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,16 @@ def _get_op_name(op, special):

_add_example_FRAME = """
>>> a = pd.DataFrame([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'],
columns=['one'])
... columns=['one'])
>>> a
one
a 1.0
b 1.0
c 1.0
d NaN
>>> b = pd.DataFrame(dict(one=[1, np.nan, 1, np.nan],
two=[np.nan, 2, np.nan, 2]),
index=['a', 'b', 'd', 'e'])
... two=[np.nan, 2, np.nan, 2]),
... index=['a', 'b', 'd', 'e'])
>>> b
one two
a 1.0 NaN
Expand Down Expand Up @@ -520,16 +520,16 @@ def _get_op_name(op, special):
Examples
--------
>>> a = pd.DataFrame([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'],
columns=['one'])
... columns=['one'])
>>> a
one
a 1.0
b 1.0
c 1.0
d NaN
>>> b = pd.DataFrame(dict(one=[1, np.nan, 1, np.nan],
two=[np.nan, 2, np.nan, 2]),
index=['a', 'b', 'd', 'e'])
... two=[np.nan, 2, np.nan, 2]),
... index=['a', 'b', 'd', 'e'])
>>> b
one two
a 1.0 NaN
Expand All @@ -556,14 +556,14 @@ def _get_op_name(op, special):
other : Series, DataFrame, or constant
axis : {{0, 1, 'index', 'columns'}}
For Series input, axis to match Series index on
level : int or name
Copy link
Contributor

Choose a reason for hiding this comment

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

I think level : int or str, though we're inconsistent here.

@jorisvandenbossche what should our policy be on index positions or labels? In principle, int or str isn't quite right since index labels needn't be strings. It'd be int or object, which isn't that informative. int or label?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yes, this is a dubious one. "name" is technically not a 'type', but "str" would not be correct as you say. So maybe better to keep it that way.

If we keep the 'name' or 'label', wouldn't 'name' be better because it is here a index level name, not a label inside the index ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes you're right I was mistaken.

And we can declare that "name" means anything that can go in {.index,.columns}{.name,.names}.

Broadcast across a level, matching Index values on the
passed MultiIndex level
fill_value : None or float value, default None
Fill existing missing (NaN) values, and any new element needed for
successful DataFrame alignment, with this value before computation.
If data in both corresponding DataFrame locations is missing
the result will be missing
level : int or name
Broadcast across a level, matching Index values on the
passed MultiIndex level

Notes
-----
Expand Down