@@ -1116,9 +1116,8 @@ def str_split(arr, pat=None, n=None):
1116
1116
1117
1117
Returns
1118
1118
-------
1119
- split : Series/Index or DataFrame/MultiIndex of objects
1120
- Type matches caller unless ``expand=True`` (return type is DataFrame or
1121
- MultiIndex)
1119
+ Series, Index, DataFrame or MultiIndex
1120
+ Type matches caller unless ``expand=True`` (see Notes).
1122
1121
1123
1122
Notes
1124
1123
-----
@@ -1129,6 +1128,16 @@ def str_split(arr, pat=None, n=None):
1129
1128
- If for a certain row the number of found splits < `n`,
1130
1129
append `None` for padding up to `n` if ``expand=True``
1131
1130
1131
+ If using ``expand=True``, Series and Index callers return DataFrame and
1132
+ MultiIndex objects, respectively.
1133
+
1134
+ See Also
1135
+ --------
1136
+ str.split : Standard library version of this method.
1137
+ Series.str.get_dummies : Split each string into dummy variables.
1138
+ Series.str.partition : Split string on a separator, returning
1139
+ the before, separator, and after components.
1140
+
1132
1141
Examples
1133
1142
--------
1134
1143
>>> s = pd.Series(["this is good text", "but this is even better"])
@@ -1145,8 +1154,10 @@ def str_split(arr, pat=None, n=None):
1145
1154
1 [but this is even better]
1146
1155
dtype: object
1147
1156
1148
- When using ``expand=True``, the split elements will
1149
- expand out into separate columns.
1157
+ When using ``expand=True``, the split elements will expand out into
1158
+ separate columns.
1159
+
1160
+ For Series object, output return type is DataFrame.
1150
1161
1151
1162
>>> s.str.split(expand=True)
1152
1163
0 1 2 3 4
@@ -1157,6 +1168,13 @@ def str_split(arr, pat=None, n=None):
1157
1168
0 this good text
1158
1169
1 but this even better
1159
1170
1171
+ For Index object, output return type is MultiIndex.
1172
+
1173
+ >>> i = pd.Index(["ba 100 001", "ba 101 002", "ba 102 003"])
1174
+ >>> i.str.split(expand=True)
1175
+ MultiIndex(levels=[['ba'], ['100', '101', '102'], ['001', '002', '003']],
1176
+ labels=[[0, 0, 0], [0, 1, 2], [0, 1, 2]])
1177
+
1160
1178
Parameter `n` can be used to limit the number of splits in the output.
1161
1179
1162
1180
>>> s.str.split("is", n=1)
0 commit comments