@@ -652,9 +652,9 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True):
652
652
To get the idea:
653
653
654
654
>>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f', repr)
655
- 0 <_sre.SRE_Match object; span=(0, 1), match='f'>oo
656
- 1 <_sre.SRE_Match object; span=(0, 1), match='f'>uz
657
- 2 NaN
655
+ 0 <re.Match object; span=(0, 1), match='f'>oo
656
+ 1 <re.Match object; span=(0, 1), match='f'>uz
657
+ 2 NaN
658
658
dtype: object
659
659
660
660
Reverse every lowercase alphabetic word:
@@ -2076,8 +2076,18 @@ class StringMethods(NoNewAttributesMixin):
2076
2076
2077
2077
Examples
2078
2078
--------
2079
- >>> s.str.split('_')
2080
- >>> s.str.replace('_', '')
2079
+ >>> s = pd.Series(["A_Str_Series"])
2080
+ >>> s
2081
+ 0 A_Str_Series
2082
+ dtype: object
2083
+
2084
+ >>> s.str.split("_")
2085
+ 0 [A, Str, Series]
2086
+ dtype: object
2087
+
2088
+ >>> s.str.replace("_", "")
2089
+ 0 AStrSeries
2090
+ dtype: object
2081
2091
"""
2082
2092
2083
2093
def __init__ (self , data ):
@@ -2583,9 +2593,14 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
2583
2593
2584
2594
Examples
2585
2595
--------
2586
- >>> s = pd.Series(["this is a regular sentence",
2587
- ... "https://docs.python.org/3/tutorial/index.html",
2588
- ... np.nan])
2596
+ >>> s = pd.Series(
2597
+ ... [
2598
+ ... "this is a regular sentence",
2599
+ ... "https://docs.python.org/3/tutorial/index.html",
2600
+ ... np.nan
2601
+ ... ]
2602
+ ... )
2603
+ >>> s
2589
2604
0 this is a regular sentence
2590
2605
1 https://docs.python.org/3/tutorial/index.html
2591
2606
2 NaN
@@ -2625,7 +2640,7 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
2625
2640
2626
2641
The `pat` parameter can be used to split by other characters.
2627
2642
2628
- >>> s.str.split(pat = "/")
2643
+ >>> s.str.split(pat= "/")
2629
2644
0 [this is a regular sentence]
2630
2645
1 [https:, , docs.python.org, 3, tutorial, index...
2631
2646
2 NaN
@@ -2636,14 +2651,10 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
2636
2651
the columns during the split.
2637
2652
2638
2653
>>> s.str.split(expand=True)
2639
- 0 1 2 3
2640
- 0 this is a regular
2641
- 1 https://docs.python.org/3/tutorial/index.html None None None
2642
- 2 NaN NaN NaN NaN \
2643
- 4
2644
- 0 sentence
2645
- 1 None
2646
- 2 NaN
2654
+ 0 1 2 3 4
2655
+ 0 this is a regular sentence
2656
+ 1 https://docs.python.org/3/tutorial/index.html None None None None
2657
+ 2 NaN NaN NaN NaN NaN
2647
2658
2648
2659
For slightly more complex use cases like splitting the html document name
2649
2660
from a url, a combination of parameter settings can be used.
@@ -2658,7 +2669,9 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
2658
2669
expressions.
2659
2670
2660
2671
>>> s = pd.Series(["1+1=2"])
2661
-
2672
+ >>> s
2673
+ 0 1+1=2
2674
+ dtype: object
2662
2675
>>> s.str.split(r"\+|=", expand=True)
2663
2676
0 1 2
2664
2677
0 1 1 2
@@ -2750,7 +2763,7 @@ def rsplit(self, pat=None, n=-1, expand=False):
2750
2763
>>> idx.str.partition()
2751
2764
MultiIndex([('X', ' ', '123'),
2752
2765
('Y', ' ', '999')],
2753
- dtype='object' )
2766
+ )
2754
2767
2755
2768
Or an index with tuples with ``expand=False``:
2756
2769
0 commit comments