@@ -1095,24 +1095,60 @@ def str_pad(arr, width, side='left', fillchar=' '):
1095
1095
1096
1096
def str_split (arr , pat = None , n = None ):
1097
1097
"""
1098
- Split each string (a la re.split) in the Series/Index by given
1099
- pattern, propagating NA values. Equivalent to :meth:`str.split`.
1098
+ Split strings around given separator/delimiter.
1099
+
1100
+ Split each string in the Series/Index by given
1101
+ pattern, propagating NaN values. Equivalent to :meth:`str.split`.
1100
1102
1101
1103
Parameters
1102
1104
----------
1103
1105
pat : string, default None
1104
- String or regular expression to split on. If None, splits on whitespace
1106
+ String or regular expression to split on.\
1107
+ If `None`, split on whitespace.
1105
1108
n : int, default -1 (all)
1106
- None, 0 and -1 will be interpreted as return all splits
1109
+ Vary dimensionality of output.
1110
+
1111
+ * `None`, 0 and -1 will be interpreted as return all splits
1107
1112
expand : bool, default False
1108
- * If True, return DataFrame/MultiIndex expanding dimensionality.
1109
- * If False, return Series/Index.
1113
+ Expand the split strings into separate columns.
1110
1114
1111
- return_type : deprecated, use `expand`
1115
+ * If `True`, return DataFrame/MultiIndex expanding dimensionality.
1116
+ * If `False`, return Series/Index.
1112
1117
1113
1118
Returns
1114
1119
-------
1115
1120
split : Series/Index or DataFrame/MultiIndex of objects
1121
+
1122
+ Notes
1123
+ -----
1124
+ If `expand` parameter is `True` and:
1125
+ - If n >= default splits, makes all splits
1126
+ - If n < default splits, makes first n splits only
1127
+ - Appends `None` for padding.
1128
+
1129
+ Examples
1130
+ --------
1131
+ >>> s = pd.Series(["this is good text", "but this is even better"])
1132
+ >>> s.str.split()
1133
+ 0 [this, is, good, text]
1134
+ 1 [but, this, is, even, better]
1135
+ dtype: object
1136
+ >>> s.str.split("random")
1137
+ 0 [this is good text]
1138
+ 1 [but this is even better]
1139
+ dtype: object
1140
+ >>> s.str.split(expand=True)
1141
+ 0 1 2 3 4
1142
+ 0 this is good text None
1143
+ 1 but this is even better
1144
+ >>> s.str.split(" is ", expand=True)
1145
+ 0 1
1146
+ 0 this good text
1147
+ 1 but this even better
1148
+ >>> s.str.split("is", n=1, expand=True)
1149
+ 0 1
1150
+ 0 th is good text
1151
+ 1 but th is even better
1116
1152
"""
1117
1153
if pat is None :
1118
1154
if n is None or n == 0 :
0 commit comments