@@ -1343,24 +1343,7 @@ def str_pad(arr, width, side='left', fillchar=' '):
1343
1343
1344
1344
1345
1345
def str_split (arr , pat = None , n = None ):
1346
- """
1347
- Split strings around given separator/delimiter.
1348
-
1349
- Parameters
1350
- ----------
1351
- pat : str, optional
1352
- String or regular expression to split on; If not specified,
1353
- split on whitespace.
1354
- n : int, default -1 (all)
1355
- Limit number of splits in output; ``None``, 0 and -1 will
1356
- be interpreted as return all splits.
1357
- expand : bool, default False
1358
- Expand the splitted strings into separate columns.
1359
-
1360
- Returns
1361
- -------
1362
- Series, Index, DataFrame or MultiIndex
1363
- """
1346
+
1364
1347
if pat is None :
1365
1348
if n is None or n == 0 :
1366
1349
n = - 1
@@ -1380,24 +1363,7 @@ def str_split(arr, pat=None, n=None):
1380
1363
1381
1364
1382
1365
def str_rsplit (arr , pat = None , n = None ):
1383
- """
1384
- Split strings around given separator/delimiter (starting from
1385
- the right).
1386
-
1387
- Parameters
1388
- ----------
1389
- pat : string, default None
1390
- Separator to split on; If None, splits on whitespace.
1391
- n : int, default -1 (all)
1392
- None, 0 and -1 will be interpreted as return all splits.
1393
- expand : bool, default False
1394
- If True, return DataFrame/MultiIndex expanding dimensionality.
1395
- If False, return Series/Index.
1396
-
1397
- Returns
1398
- -------
1399
- Series/Index or DataFrame/MultiIndex of objects
1400
- """
1366
+
1401
1367
if n is None or n == 0 :
1402
1368
n = - 1
1403
1369
f = lambda x : x .rsplit (pat , n )
@@ -2279,33 +2245,36 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
2279
2245
2280
2246
See Also
2281
2247
--------
2282
- %(also)s
2248
+ split : Splits string at the first occurrence of delimiter
2249
+ rsplit : Splits string at the last occurrence of delimiter
2283
2250
2284
2251
Examples
2285
2252
--------
2286
- %(example)s
2287
- """ )
2253
+ >>> s = pd.Series(["this is good text", "but this is even better"])
2288
2254
2289
- @Appender (_shared_docs ['str_split' ] % {
2290
- 'side' : 'beginning' ,
2291
- 'method' : 'split' ,
2292
- 'also' : 'rsplit : Splits string at the last occurrence of delimiter' ,
2293
- 'example' :
2294
- """>>> s = pd.Series(["this is good text", "but this is even better"])
2295
-
2296
- By default, split will return an object of the same size
2255
+ By default, split and rsplit will return an object of the same size
2297
2256
having lists containing the split elements
2298
2257
2299
2258
>>> s.str.split()
2300
2259
0 [this, is, good, text]
2301
2260
1 [but, this, is, even, better]
2302
2261
dtype: object
2303
2262
2263
+ >>> s.str.rsplit()
2264
+ 0 [this, is, good, text]
2265
+ 1 [but, this, is, even, better]
2266
+ dtype: object
2267
+
2304
2268
>>> s.str.split("random")
2305
2269
0 [this is good text]
2306
2270
1 [but this is even better]
2307
2271
dtype: object
2308
2272
2273
+ >>> s.str.rsplit("random")
2274
+ 0 [this is good text]
2275
+ 1 [but this is even better]
2276
+ dtype: object
2277
+
2309
2278
When using ``expand=True``, the split and rsplit elements will
2310
2279
expand out into separate columns.
2311
2280
@@ -2328,6 +2297,11 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
2328
2297
1 [but th, is even better]
2329
2298
dtype: object
2330
2299
2300
+ >>> s.str.rsplit("is", n=1)
2301
+ 0 [this , good text]
2302
+ 1 [but this , even better]
2303
+ dtype: object
2304
+
2331
2305
If NaN is present, it is propagated throughout the columns
2332
2306
during the split.
2333
2307
@@ -2337,48 +2311,27 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
2337
2311
0 1 2 3
2338
2312
0 this is good text
2339
2313
1 but this is even better
2340
- 2 NaN NaN NaN NaN """ })
2314
+ 2 NaN NaN NaN NaN
2315
+
2316
+ >>> s.str.rsplit(n=3, expand=True)
2317
+ 0 1 2 3
2318
+ 0 this is good text
2319
+ 1 but this is even better
2320
+ 2 NaN NaN NaN NaN
2321
+ """ )
2322
+
2323
+ @Appender (_shared_docs ['str_split' ] % {
2324
+ 'side' : 'beginning' ,
2325
+ 'method' : 'split'
2326
+ })
2341
2327
def split (self , pat = None , n = - 1 , expand = False ):
2342
2328
result = str_split (self ._data , pat , n = n )
2343
2329
return self ._wrap_result (result , expand = expand )
2344
2330
2345
2331
@Appender (_shared_docs ['str_split' ] % {
2346
2332
'side' : 'end' ,
2347
- 'method' : 'rsplit' ,
2348
- 'also' : 'split : Splits string at the first occurrence of delimiter' ,
2349
- 'example' :
2350
- """>>> s = pd.Series(["this is good text", "but this is even better"])
2351
-
2352
- By default, rsplit will return an object of the same size
2353
- having lists containing the split elements
2354
-
2355
- >>> s.str.rsplit()
2356
- 0 [this, is, good, text]
2357
- 1 [but, this, is, even, better]
2358
- dtype: object
2359
-
2360
- >>> s.str.rsplit("random")
2361
- 0 [this is good text]
2362
- 1 [but this is even better]
2363
- dtype: object
2364
-
2365
- Parameter `n` can be used to limit the number of splits in the output.
2366
-
2367
- >>> s.str.rsplit("is", n=1)
2368
- 0 [this , good text]
2369
- 1 [but this , even better]
2370
- dtype: object
2371
-
2372
- If NaN is present, it is propagated throughout the columns
2373
- during the split.
2374
-
2375
- >>> s = pd.Series(["this is good text", "but this is even better", np.nan])
2376
-
2377
- >>> s.str.rsplit(n=3, expand=True)
2378
- 0 1 2 3
2379
- 0 this is good text
2380
- 1 but this is even better
2381
- 2 NaN NaN NaN NaN """ })
2333
+ 'method' : 'rsplit'
2334
+ })
2382
2335
def rsplit (self , pat = None , n = - 1 , expand = False ):
2383
2336
result = str_rsplit (self ._data , pat , n = n )
2384
2337
return self ._wrap_result (result , expand = expand )
0 commit comments