Skip to content

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

Merged
merged 6 commits into from
Mar 14, 2018
Merged
Changes from 4 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
22 changes: 15 additions & 7 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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?

Copy link
Contributor Author

@vipinkjonwal vipinkjonwal Mar 10, 2018

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 :

pd.Series(['a', 'b', 'c']).str.cat(['A', 'B', 'C'], sep=',')
index
0 a,A (a with A i.e, 0th index of list in Series and 0th index of list in cat(list...) )
1 b,B (b with B)
2 c,C (c with C)

Copy link
Member

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"

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
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 add , optional at the end of the line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

I would also say something here about not passing other that then all values in the Series are concatenated in a single string (so to indicate you first give an example of this part of the behaviour of the method)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added :-)

Copy link
Member

Choose a reason for hiding this comment

The 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=' ')
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 split this example in two steps?

s = pd.Series(...)
s.str.cat(sep=..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down