From cad3c8e4d5a324df9a17c47465278dfe739670c5 Mon Sep 17 00:00:00 2001 From: Vipin Kumar Date: Sat, 10 Mar 2018 19:59:17 +0530 Subject: [PATCH 1/6] Update str_cat Documentation --- pandas/core/strings.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 6b427ed1da834..8ab588f73fc4f 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -51,11 +51,16 @@ 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 - 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,16 +73,16 @@ def str_cat(arr, others=None, sep=None, na_rep=None): When ``na_rep`` is `None` (default behavior), NaN value(s) in the Series are ignored. - >>> Series(['a','b',np.nan,'c']).str.cat(sep=' ') + >>> pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ') '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 @@ -85,12 +90,12 @@ def str_cat(arr, others=None, sep=None, na_rep=None): 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 From 0e60df6aa6bfbefaf56c8f4a46d921e930cd206c Mon Sep 17 00:00:00 2001 From: Vipin Kumar Date: Sat, 10 Mar 2018 20:10:15 +0530 Subject: [PATCH 2/6] Update str_cat Documentation --- pandas/core/strings.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 8ab588f73fc4f..596b744f6bfe6 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -51,9 +51,12 @@ 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. + 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 ---------- From d0c56ef77e2ba0acaacf5cff1906420d19b62484 Mon Sep 17 00:00:00 2001 From: Vipin Kumar Date: Sat, 10 Mar 2018 20:14:23 +0530 Subject: [PATCH 3/6] Update str_cat Documentation --- pandas/core/strings.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 596b744f6bfe6..843c85be299c9 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -52,10 +52,10 @@ 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` + 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 @@ -66,7 +66,7 @@ def str_cat(arr, others=None, sep=None, na_rep=None): If None, concatenates without any separator. na_rep : string or None, default None If None, NA in the series are ignored. - + Returns ------- concat : Series/Index of objects or str From 429b5004c4326e6e4c36d9f7168754c03d1f1d5f Mon Sep 17 00:00:00 2001 From: Vipin Kumar Date: Sat, 10 Mar 2018 20:17:38 +0530 Subject: [PATCH 4/6] Update str_cat Documentation --- pandas/core/strings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 843c85be299c9..45c641df6a1cc 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -51,7 +51,7 @@ 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 + 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 @@ -66,7 +66,7 @@ def str_cat(arr, others=None, sep=None, na_rep=None): If None, concatenates without any separator. na_rep : string or None, default None If None, NA in the series are ignored. - + Returns ------- concat : Series/Index of objects or str From 6ff587f4ff5480e8e72eea6f1034681b0a77a301 Mon Sep 17 00:00:00 2001 From: Vipin Kumar Date: Sun, 11 Mar 2018 00:06:31 +0530 Subject: [PATCH 5/6] DOC : Update cat_str --- pandas/core/strings.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 45c641df6a1cc..76939ea04b722 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -55,14 +55,16 @@ def str_cat(arr, others=None, sep=None, na_rep=None): 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. + are present. If `others` is not being passed then + all values in the Series are concatenated in a single string. + The final concatenation is done with a given `sep` + and a string is returned, `sep` is optional. Parameters ---------- others : list-like, or list of list-likes If None, returns str concatenating strings of the Series. - sep : string or None, default None. + 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. @@ -71,12 +73,17 @@ def str_cat(arr, others=None, sep=None, na_rep=None): ------- concat : Series/Index of objects or str + See Also + -------- + str_split : Split each string in the Series/Index + Examples -------- When ``na_rep`` is `None` (default behavior), NaN value(s) in the Series are ignored. - >>> pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ') + >>> s = pd.Series(['a','b',np.nan,'c']) + >>> s.str.cat(sep=' ') 'a b c' >>> pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ', na_rep='?') From 7aa5ea74d2a8ddd2efba0fbafb21dddd4fa5866d Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 14 Mar 2018 15:36:22 +0100 Subject: [PATCH 6/6] simplify extended summary --- pandas/core/strings.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 76939ea04b722..d6ea5d0e4bf0d 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -51,18 +51,15 @@ 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. If `others` is not being passed then - all values in the Series are concatenated in a single string. - The final concatenation is done with a given `sep` - and a string is returned, `sep` is optional. + If `others` is specified, this function concatenates the Series/Index + and elements of `others` element-wise. + If `others` is not being passed then all values in the Series are + concatenated in a single string with a given `sep`. Parameters ---------- - others : list-like, or list of list-likes + others : list-like, or list of list-likes, optional + List-likes (or a list of them) of the same length as calling object. If None, returns str concatenating strings of the Series. sep : string or None, default None If None, concatenates without any separator. @@ -75,21 +72,24 @@ def str_cat(arr, others=None, sep=None, na_rep=None): See Also -------- - str_split : Split each string in the Series/Index + split : Split each string in the Series/Index Examples -------- - When ``na_rep`` is `None` (default behavior), NaN value(s) - in the Series are ignored. + When not passing `other`, all values are concatenated into a single + string: - >>> s = pd.Series(['a','b',np.nan,'c']) + >>> s = pd.Series(['a', 'b', np.nan, 'c']) >>> s.str.cat(sep=' ') 'a b c' - >>> pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ', na_rep='?') + By default, NA values in the Series are ignored. Using `na_rep`, they + can be given a representation: + + >>> pd.Series(['a', 'b', np.nan, 'c']).str.cat(sep=' ', na_rep='?') 'a b ? c' - If ``others`` is specified, corresponding values are + If `others` is specified, corresponding values are concatenated with the separator. Result will be a Series of strings. >>> pd.Series(['a', 'b', 'c']).str.cat(['A', 'B', 'C'], sep=',') @@ -98,11 +98,6 @@ def str_cat(arr, others=None, sep=None, na_rep=None): 2 c,C dtype: object - Otherwise, strings in the Series are concatenated. Result will be a string. - - >>> pd.Series(['a', 'b', 'c']).str.cat(sep=',') - 'a,b,c' - Also, you can pass a list of list-likes. >>> pd.Series(['a', 'b']).str.cat([['x', 'y'], ['1', '2']], sep=',')