@@ -2210,7 +2210,7 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
22102210 Split strings around given separator/delimiter.
22112211
22122212 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`.
22142214
22152215 Parameters
22162216 ----------
@@ -2245,93 +2245,87 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
22452245
22462246 See Also
22472247 --------
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.
22492255
22502256 Examples
22512257 --------
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 ])
22532259
22542260 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.
22562265
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
22602270 dtype: object
22612271
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
22652276 dtype: object
22662277
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
22702282 dtype: object
22712283
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
22752288 dtype: object
22762289
22772290 When using ``expand=True``, the split and rsplit elements will
22782291 expand out into separate columns.
22792292
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
23202316 """ )
23212317
23222318 @Appender (_shared_docs ['str_split' ] % {
23232319 'side' : 'beginning' ,
2324- 'method' : 'split' ,
2325- 'also' : 'rsplit : Splits string at the last occurrence of delimiter'
2320+ 'method' : 'split'
23262321 })
23272322 def split (self , pat = None , n = - 1 , expand = False ):
23282323 result = str_split (self ._data , pat , n = n )
23292324 return self ._wrap_result (result , expand = expand )
23302325
23312326 @Appender (_shared_docs ['str_split' ] % {
23322327 'side' : 'end' ,
2333- 'method' : 'rsplit' ,
2334- 'also' : 'split : Splits string at the first occurrence of delimiter'
2328+ 'method' : 'rsplit'
23352329 })
23362330 def rsplit (self , pat = None , n = - 1 , expand = False ):
23372331 result = str_rsplit (self ._data , pat , n = n )
0 commit comments