-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update docstring of pandas.Series.add_prefix docstring #20313
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 3 commits
5e780e9
397f05d
c719d7a
e14315d
f23e340
177285d
67c8dbe
6d599ad
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 |
---|---|---|
|
@@ -2963,15 +2963,37 @@ def _update_inplace(self, result, verify_is_copy=True): | |
|
||
def add_prefix(self, prefix): | ||
""" | ||
Concatenate prefix string with panel items names. | ||
Concatenate prefix string with Series items names. | ||
|
||
Parameters | ||
---------- | ||
prefix : string | ||
prefix : str | ||
The string to add before each item name. | ||
|
||
Returns | ||
------- | ||
with_prefix : type of caller | ||
Series | ||
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.
|
||
Original Series with updated item names. | ||
|
||
See Also | ||
-------- | ||
Series.add_suffix: Add a suffix string to Series items names. | ||
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. "items names" -> "row labels" 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 see your point for "item names", please check the comment above related to include DataFrame or not (if not could make the change to "row labels" suggested 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. So anywhere we say "item names", let's say "labels." or "row labels" or "column labels". |
||
|
||
Examples | ||
-------- | ||
>>> s = pd.Series([1, 2, 3, 4]) | ||
>>> s | ||
0 1 | ||
1 2 | ||
2 3 | ||
3 4 | ||
dtype: int64 | ||
>>> s.add_prefix('item_') | ||
item_0 1 | ||
item_1 2 | ||
item_2 3 | ||
item_3 4 | ||
dtype: int64 | ||
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. Add a blank line and then an example with |
||
""" | ||
new_data = self._data.add_prefix(prefix) | ||
return self._constructor(new_data).__finalize__(self) | ||
|
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.
Panel
is deprecated, we may want to useSeries or DataFrame
, or something generic.I'd try to find uses cases on the internet for this method, and add in the extended summary when this method can be useful, if possible.
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.
Thanks! I used Series as it is a Series module in this case.
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.
For this and #20315, these apply to both Series and DataFrame (and Panel, but we don't care about that). So perhaps
I want to avoid
items
, as (to me) I thinkdict.items
so key-value pairs. But we're just touching the row labels here.That summary is strange since we use Prefix as a verb and nound. Maybe "Prepend" would be better?
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.
I see, thank you, my doubt is that on DataFrames add_prefix() adds a prefix on columns names not on rows, for example:
df = pd.DataFrame({'A':[1,2,3,4], 'B':[3,4,5,6]}), df.add_suffix('_item')
. For this motivations I decided to leave on Series.Perhaps I could updated the docstring for pandas.DataFrame.add_prefix with the relative example to avoid confusion and let this as it is.
Let me know what sound better. :)
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.
Ahh, good catch! I would say splitting the docstring is more complexity that warranted. How about somehting like
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.
Yes, I do agree, thanks!
I didn't know about the issue of splitting docstring, so in this case is better have the same for both pandas.Series.add_prefix and pandas.DataFrame.add_prefix?
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.
Yes, the docstring you've been editing in
core/generic.py
is used by bothSeries.add_prefix
andDataFrame.add_prefix
.