@@ -1231,7 +1231,7 @@ def replace(self, pat, repl, n=-1, case=None, flags=0, regex=None):
1231
1231
Regex module flags, e.g. re.IGNORECASE. Cannot be set if `pat` is a compiled
1232
1232
regex.
1233
1233
regex : bool, default True
1234
- Determines if assumes the passed-in pattern is a regular expression:
1234
+ Determines if the passed-in pattern is a regular expression:
1235
1235
1236
1236
- If True, assumes the passed-in pattern is a regular expression.
1237
1237
- If False, treats the pattern as a literal string
@@ -1287,7 +1287,7 @@ def replace(self, pat, repl, n=-1, case=None, flags=0, regex=None):
1287
1287
1288
1288
To get the idea:
1289
1289
1290
- >>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f', repr)
1290
+ >>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f', repr, regex=True )
1291
1291
0 <re.Match object; span=(0, 1), match='f'>oo
1292
1292
1 <re.Match object; span=(0, 1), match='f'>uz
1293
1293
2 NaN
@@ -1296,7 +1296,8 @@ def replace(self, pat, repl, n=-1, case=None, flags=0, regex=None):
1296
1296
Reverse every lowercase alphabetic word:
1297
1297
1298
1298
>>> repl = lambda m: m.group(0)[::-1]
1299
- >>> pd.Series(['foo 123', 'bar baz', np.nan]).str.replace(r'[a-z]+', repl)
1299
+ >>> ser = pd.Series(['foo 123', 'bar baz', np.nan])
1300
+ >>> ser.str.replace(r'[a-z]+', repl, regex=True)
1300
1301
0 oof 123
1301
1302
1 rab zab
1302
1303
2 NaN
@@ -1306,7 +1307,8 @@ def replace(self, pat, repl, n=-1, case=None, flags=0, regex=None):
1306
1307
1307
1308
>>> pat = r"(?P<one>\w+) (?P<two>\w+) (?P<three>\w+)"
1308
1309
>>> repl = lambda m: m.group('two').swapcase()
1309
- >>> pd.Series(['One Two Three', 'Foo Bar Baz']).str.replace(pat, repl)
1310
+ >>> ser = pd.Series(['One Two Three', 'Foo Bar Baz'])
1311
+ >>> ser.str.replace(pat, repl, regex=True)
1310
1312
0 tWO
1311
1313
1 bAR
1312
1314
dtype: object
@@ -1315,7 +1317,7 @@ def replace(self, pat, repl, n=-1, case=None, flags=0, regex=None):
1315
1317
1316
1318
>>> import re
1317
1319
>>> regex_pat = re.compile(r'FUZ', flags=re.IGNORECASE)
1318
- >>> pd.Series(['foo', 'fuz', np.nan]).str.replace(regex_pat, 'bar')
1320
+ >>> pd.Series(['foo', 'fuz', np.nan]).str.replace(regex_pat, 'bar', regex=True )
1319
1321
0 foo
1320
1322
1 bar
1321
1323
2 NaN
0 commit comments