@@ -1095,24 +1095,83 @@ def str_pad(arr, width, side='left', fillchar=' '):
10951095
10961096def str_split (arr , pat = None , n = None ):
10971097 """
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 str in the caller's values by given
1101+ pattern, propagating NaN values. Equivalent to :meth:`str.split`.
11001102
11011103 Parameters
11021104 ----------
11031105 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.
11051108 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
11071112 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.
11101114
1111- return_type : deprecated, use `expand`
1115+ * If `True`, return DataFrame/MultiIndex expanding dimensionality.
1116+ * If `False`, return Series/Index.
11121117
11131118 Returns
11141119 -------
1120+ Type matches caller unless `expand=True` (return type is `DataFrame`)
11151121 split : Series/Index or DataFrame/MultiIndex of objects
1122+
1123+ Notes
1124+ -----
1125+ If `expand` parameter is `True` and:
1126+ - If n >= default splits, makes all splits
1127+ - If n < default splits, makes first n splits only
1128+ - Appends `None` for padding.
1129+
1130+ Examples
1131+ --------
1132+ >>> s = pd.Series(["this is good text", "but this is even better"])
1133+
1134+ By default, split will return an object of the same size
1135+ having lists containing the split elements
1136+
1137+ >>> s.str.split()
1138+ 0 [this, is, good, text]
1139+ 1 [but, this, is, even, better]
1140+ dtype: object
1141+ >>> s.str.split("random")
1142+ 0 [this is good text]
1143+ 1 [but this is even better]
1144+ dtype: object
1145+
1146+ When using `expand=True`, the split elements will
1147+ expand out into separate columns.
1148+
1149+ >>> s.str.split(expand=True)
1150+ 0 1 2 3 4
1151+ 0 this is good text None
1152+ 1 but this is even better
1153+ >>> s.str.split(" is ", expand=True)
1154+ 0 1
1155+ 0 this good text
1156+ 1 but this even better
1157+
1158+ Parameter `n` can be used to limit the number of columns in
1159+ expansion of output.
1160+
1161+ >>> s.str.split("is", n=1, expand=True)
1162+ 0 1
1163+ 0 th is good text
1164+ 1 but th is even better
1165+
1166+ If NaN is present, it is propagated throughout the columns
1167+ during the split.
1168+
1169+ >>> s = pd.Series(["this is good text", "but this is even better", np.nan])
1170+ >>> s.str.split(n=3, expand=True)
1171+ 0 1 2 3
1172+ 0 this is good text
1173+ 1 but this is even better
1174+ 2 NaN NaN NaN NaN
11161175 """
11171176 if pat is None :
11181177 if n is None or n == 0 :
0 commit comments