@@ -2210,7 +2210,7 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
2210
2210
Split strings around given separator/delimiter.
2211
2211
2212
2212
Splits the string in the Series/Index from the %(side)s,
2213
- at the specified delimiter string.Equivalent to :meth:`str.%(method)s`.
2213
+ at the specified delimiter string. Equivalent to :meth:`str.%(method)s`.
2214
2214
2215
2215
Parameters
2216
2216
----------
@@ -2245,93 +2245,87 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
2245
2245
2246
2246
See Also
2247
2247
--------
2248
- %(also)s
2248
+ Series.str.split : Split strings around given separator/delimiter.
2249
+ Series.str.rsplit : Splits string around given separator/delimiter, starting from
2250
+ the right.
2251
+ Series.str.join : Join lists contained as elements in the Series/Index
2252
+ with passed delimiter.
2253
+ str.split : Standard library version for split.
2254
+ str.rsplit : Standard library version for rsplit.
2249
2255
2250
2256
Examples
2251
2257
--------
2252
- >>> s = pd.Series(["this is good text ", "but this is even better" ])
2258
+ >>> s = pd.Series(["this is a regular sentence ", "this,is,comma,separated,text", np.nan ])
2253
2259
2254
2260
By default, split and rsplit will return an object of the same size
2255
- having lists containing the split elements
2261
+ having lists containing the split elements.
2262
+
2263
+ Parameter `n` can be used to limit the number of splits on the delimiter. If delimiter is
2264
+ not specified, string is split on whitespace.
2256
2265
2257
- >>> s.str.split()
2258
- 0 [this, is, good, text]
2259
- 1 [but, this, is, even, better]
2266
+ >>> s.str.split(n=2)
2267
+ 0 [this, is, a regular sentence]
2268
+ 1 [this,is,comma,separated,text]
2269
+ 2 NaN
2260
2270
dtype: object
2261
2271
2262
- >>> s.str.rsplit()
2263
- 0 [this, is, good, text]
2264
- 1 [but, this, is, even, better]
2272
+ >>> s.str.rsplit(n=2)
2273
+ 0 [this is a, regular, sentence]
2274
+ 1 [this,is,comma,separated,text]
2275
+ 2 NaN
2265
2276
dtype: object
2266
2277
2267
- >>> s.str.split("random")
2268
- 0 [this is good text]
2269
- 1 [but this is even better]
2278
+ >>> s.str.split(",", n=2)
2279
+ 0 [this is a regular sentence]
2280
+ 1 [this, is, comma,separated,text]
2281
+ 2 NaN
2270
2282
dtype: object
2271
2283
2272
- >>> s.str.rsplit("random")
2273
- 0 [this is good text]
2274
- 1 [but this is even better]
2284
+ >>> s.str.rsplit(",", n=2)
2285
+ 0 [this is a regular sentence]
2286
+ 1 [this,is,comma, separated, text]
2287
+ 2 NaN
2275
2288
dtype: object
2276
2289
2277
2290
When using ``expand=True``, the split and rsplit elements will
2278
2291
expand out into separate columns.
2279
2292
2280
- For Series object, output return type is DataFrame.
2281
-
2282
- >>> s.str.split(expand=True)
2283
- 0 1 2 3 4
2284
- 0 this is good text None
2285
- 1 but this is even better
2286
-
2287
- >>> s.str.split(" is ", expand=True)
2288
- 0 1
2289
- 0 this good text
2290
- 1 but this even better
2291
-
2292
- Parameter `n` can be used to limit the number of splits in the output.
2293
-
2294
- >>> s.str.split("is", n=1)
2295
- 0 [th, is good text]
2296
- 1 [but th, is even better]
2297
- dtype: object
2298
-
2299
- >>> s.str.rsplit("is", n=1)
2300
- 0 [this , good text]
2301
- 1 [but this , even better]
2302
- dtype: object
2303
-
2304
- If NaN is present, it is propagated throughout the columns
2305
- during the split.
2306
-
2307
- >>> s = pd.Series(["this is good text", "but this is even better", np.nan])
2308
-
2309
- >>> s.str.split(n=3, expand=True)
2310
- 0 1 2 3
2311
- 0 this is good text
2312
- 1 but this is even better
2313
- 2 NaN NaN NaN NaN
2314
-
2315
- >>> s.str.rsplit(n=3, expand=True)
2316
- 0 1 2 3
2317
- 0 this is good text
2318
- 1 but this is even better
2319
- 2 NaN NaN NaN NaN
2293
+ >>> s.str.split(n=2, expand=True)
2294
+ 0 1 2
2295
+ 0 this is a regular sentence
2296
+ 1 this,is,comma,separated,text None None
2297
+ 2 NaN NaN NaN
2298
+
2299
+ >>> s.str.rsplit(n=2, expand=True)
2300
+ 0 1 2
2301
+ 0 this is a regular sentence
2302
+ 1 this,is,comma,separated,text None None
2303
+ 2 NaN NaN NaN
2304
+
2305
+ >>> s.str.split(",", n=2, expand=True)
2306
+ 0 1 2
2307
+ 0 this is a regular sentence None None
2308
+ 1 this is comma,separated,text
2309
+ 2 NaN NaN NaN
2310
+
2311
+ >>> s.str.rsplit(",", n=2, expand=True)
2312
+ 0 1 2
2313
+ 0 this is a regular sentence None None
2314
+ 1 this,is,comma separated text
2315
+ 2 NaN NaN NaN
2320
2316
""" )
2321
2317
2322
2318
@Appender (_shared_docs ['str_split' ] % {
2323
2319
'side' : 'beginning' ,
2324
- 'method' : 'split' ,
2325
- 'also' : 'rsplit : Splits string at the last occurrence of delimiter'
2320
+ 'method' : 'split'
2326
2321
})
2327
2322
def split (self , pat = None , n = - 1 , expand = False ):
2328
2323
result = str_split (self ._data , pat , n = n )
2329
2324
return self ._wrap_result (result , expand = expand )
2330
2325
2331
2326
@Appender (_shared_docs ['str_split' ] % {
2332
2327
'side' : 'end' ,
2333
- 'method' : 'rsplit' ,
2334
- 'also' : 'split : Splits string at the first occurrence of delimiter'
2328
+ 'method' : 'rsplit'
2335
2329
})
2336
2330
def rsplit (self , pat = None , n = - 1 , expand = False ):
2337
2331
result = str_rsplit (self ._data , pat , n = n )
0 commit comments