@@ -2340,47 +2340,82 @@ def rsplit(self, pat=None, n=-1, expand=False):
2340
2340
return self ._wrap_result (result , expand = expand )
2341
2341
2342
2342
_shared_docs ['str_partition' ] = ("""
2343
- Split the string at the %(side)s occurrence of `sep`, and return 3 elements
2344
- containing the part before the separator, the separator itself,
2345
- and the part after the separator.
2343
+ Split the string at the %(side)s occurrence of `sep`.
2344
+
2345
+ This method splits the string at the %(side)s occurrence of `sep`,
2346
+ and returns 3 elements containing the part before the separator,
2347
+ the separator itself, and the part after the separator.
2346
2348
If the separator is not found, return %(return)s.
2347
2349
2348
2350
Parameters
2349
2351
----------
2350
- pat : string , default whitespace
2352
+ pat : str , default whitespace
2351
2353
String to split on.
2352
2354
expand : bool, default True
2353
- * If True, return DataFrame/MultiIndex expanding dimensionality.
2354
- * If False, return Series/Index.
2355
+ If True, return DataFrame/MultiIndex expanding dimensionality.
2356
+ If False, return Series/Index.
2355
2357
2356
2358
Returns
2357
2359
-------
2358
- split : DataFrame/MultiIndex or Series/Index of objects
2360
+ DataFrame/MultiIndex or Series/Index of objects
2359
2361
2360
2362
See Also
2361
2363
--------
2362
2364
%(also)s
2365
+ Series.str.split : Split strings around given separators.
2366
+ str.partition : Standard library version.
2363
2367
2364
2368
Examples
2365
2369
--------
2366
2370
2367
- >>> s = Series(['A_B_C', 'D_E_F' , 'X '])
2368
- 0 A_B_C
2369
- 1 D_E_F
2370
- 2 X
2371
+ >>> s = pd. Series(['Linda van der Berg' , 'George Pitt-Rivers '])
2372
+ >>> s
2373
+ 0 Linda van der Berg
2374
+ 1 George Pitt-Rivers
2371
2375
dtype: object
2372
2376
2373
- >>> s.str.partition('_')
2374
- 0 1 2
2375
- 0 A _ B_C
2376
- 1 D _ E_F
2377
- 2 X
2378
-
2379
- >>> s.str.rpartition('_')
2380
- 0 1 2
2381
- 0 A_B _ C
2382
- 1 D_E _ F
2383
- 2 X
2377
+ >>> s.str.partition()
2378
+ 0 1 2
2379
+ 0 Linda van der Berg
2380
+ 1 George Pitt-Rivers
2381
+
2382
+ To partition by the last space instead of the first one:
2383
+
2384
+ >>> s.str.rpartition()
2385
+ 0 1 2
2386
+ 0 Linda van der Berg
2387
+ 1 George Pitt-Rivers
2388
+
2389
+ To partition by something different than a space:
2390
+
2391
+ >>> s.str.partition('-')
2392
+ 0 1 2
2393
+ 0 Linda van der Berg
2394
+ 1 George Pitt - Rivers
2395
+
2396
+ To return a Series containining tuples instead of a DataFrame:
2397
+
2398
+ >>> s.str.partition('-', expand=False)
2399
+ 0 (Linda van der Berg, , )
2400
+ 1 (George Pitt, -, Rivers)
2401
+ dtype: object
2402
+
2403
+ Also available on indices:
2404
+
2405
+ >>> idx = pd.Index(['X 123', 'Y 999'])
2406
+ >>> idx
2407
+ Index(['X 123', 'Y 999'], dtype='object')
2408
+
2409
+ Which will create a MultiIndex:
2410
+
2411
+ >>> idx.str.partition()
2412
+ MultiIndex(levels=[['X', 'Y'], [' '], ['123', '999']],
2413
+ labels=[[0, 1], [0, 0], [0, 1]])
2414
+
2415
+ Or an index with tuples with ``expand=False``:
2416
+
2417
+ >>> idx.str.partition(expand=False)
2418
+ Index([('X', ' ', '123'), ('Y', ' ', '999')], dtype='object')
2384
2419
""" )
2385
2420
2386
2421
@Appender (_shared_docs ['str_partition' ] % {
0 commit comments