-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the Series.str.join docstring #20463
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 4 commits
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 |
---|---|---|
|
@@ -941,17 +941,52 @@ def str_get_dummies(arr, sep='|'): | |
|
||
def str_join(arr, sep): | ||
""" | ||
Join lists contained as elements in the Series/Index with | ||
passed delimiter. Equivalent to :meth:`str.join`. | ||
Join lists contained as elements in the Series/Index with passed delimiter. | ||
|
||
If the elements of a Series are lists themselves, join the content of these | ||
lists using the delimiter passed to the function. | ||
This function is an equivalent to :meth:`str.join`. | ||
|
||
Parameters | ||
---------- | ||
sep : string | ||
Delimiter | ||
sep : str | ||
Delimiter to use between list entries. | ||
|
||
Returns | ||
------- | ||
joined : Series/Index of objects | ||
Series/Index of objects | ||
|
||
Notes | ||
----- | ||
If any of the lists does not contain string objects the result of the join | ||
will be `NaN`. | ||
|
||
See Also | ||
-------- | ||
str.join : Standard library version of this method. | ||
Series.str.split : Split strings around given separator/delimiter. | ||
|
||
Examples | ||
-------- | ||
|
||
Example with a list that contains non-string elements. | ||
|
||
>>> s = pd.Series({1: ['lion', 'elephant', 'zebra'], | ||
... 2: [1.1, 2.2, 3.3], | ||
... 3: [np.nan, np.nan, np.nan]}) | ||
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. Minor comment, but I think it'd be more useful for users to see that joining Also, it's something very subtle, but I find slightly distracting using a specific index in the example, that is not used. It surely doesn't make a big difference, but I'd construct the |
||
>>> s | ||
1 [lion, elephant, zebra] | ||
2 [1.1, 2.2, 3.3] | ||
3 [nan, nan, nan] | ||
dtype: object | ||
|
||
Join all lists using an '-', the list of floats will become a NaN. | ||
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 this comment needs to be updated after adding the |
||
|
||
>>> s.str.join('-') | ||
1 lion-elephant-zebra | ||
2 NaN | ||
3 NaN | ||
dtype: 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. I think that this second example, the first one is actually a bit redundant. As this exemplifies both cases, strings and not strings. And I think we could even show in one of the rows the floats, another the strings (both as you did), and use the third one to illustrate a list with a |
||
""" | ||
return _na_map(sep.join, arr) | ||
|
||
|
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'd use
object
instead ofobjects
, as this is more a type definition than an explanations (may be one day we can use these types as annotations?)