-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the str_cat() docstring (Delhi) #20171
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
cad3c8e
0e60df6
d0c56ef
429b500
6ff587f
7aa5ea7
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 |
---|---|---|
|
@@ -51,11 +51,19 @@ def str_cat(arr, others=None, sep=None, na_rep=None): | |
""" | ||
Concatenate strings in the Series/Index with given separator. | ||
|
||
This function concatenates elements of Series/Index and elements | ||
of lists or list-like objects having same length. | ||
The concatenation is done at corresponding indices of | ||
iterable specified by `Series` when two or more iterables | ||
are present. The final concatenation is done with a given `sep` | ||
and a string is returned. | ||
|
||
Parameters | ||
---------- | ||
others : list-like, or list of list-likes | ||
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 add 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. Yes. Adding. |
||
If None, returns str concatenating strings of the Series | ||
sep : string or None, default None | ||
If None, returns str concatenating strings of the Series. | ||
sep : string or None, default None. | ||
If None, concatenates without any separator. | ||
na_rep : string or None, default None | ||
If None, NA in the series are ignored. | ||
|
||
|
@@ -68,29 +76,29 @@ def str_cat(arr, others=None, sep=None, na_rep=None): | |
When ``na_rep`` is `None` (default behavior), NaN value(s) | ||
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 would also say something here about not passing 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. Added :-) 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. Did you add this? |
||
in the Series are ignored. | ||
|
||
>>> Series(['a','b',np.nan,'c']).str.cat(sep=' ') | ||
>>> pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ') | ||
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 split this example in two steps? s = pd.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. Yes, I can do this way as well. |
||
'a b c' | ||
|
||
>>> Series(['a','b',np.nan,'c']).str.cat(sep=' ', na_rep='?') | ||
>>> pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ', na_rep='?') | ||
'a b ? c' | ||
|
||
If ``others`` is specified, corresponding values are | ||
concatenated with the separator. Result will be a Series of strings. | ||
|
||
>>> Series(['a', 'b', 'c']).str.cat(['A', 'B', 'C'], sep=',') | ||
>>> pd.Series(['a', 'b', 'c']).str.cat(['A', 'B', 'C'], sep=',') | ||
0 a,A | ||
1 b,B | ||
2 c,C | ||
dtype: object | ||
|
||
Otherwise, strings in the Series are concatenated. Result will be a string. | ||
|
||
>>> Series(['a', 'b', 'c']).str.cat(sep=',') | ||
>>> pd.Series(['a', 'b', 'c']).str.cat(sep=',') | ||
'a,b,c' | ||
|
||
Also, you can pass a list of list-likes. | ||
|
||
>>> Series(['a', 'b']).str.cat([['x', 'y'], ['1', '2']], sep=',') | ||
>>> pd.Series(['a', 'b']).str.cat([['x', 'y'], ['1', '2']], sep=',') | ||
0 a,x,1 | ||
1 b,y,2 | ||
dtype: object | ||
|
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 part is not fully clear to me: " corresponding indices of iterable"
Can you give a small example of what you want to explain here?
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.
Corresponding indices indicates that the concatenation is being done in one to one correspondence with the indices i.e, index of iterable, let say list.
For example :
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.
Ah, OK. In that case, I think it is fine to say that "concatenates the Series/Index and
other
element-wise"