File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -168,12 +168,18 @@ positional argument (a regex object) and return a string.
168
168
169
169
# Reverse every lowercase alphabetic word
170
170
pat = r ' [a-z ]+ '
171
- repl = lambda m : m.group(0 )[::- 1 ] # noqa: E731
171
+
172
+ def repl (m ):
173
+ return m.group(0 )[::- 1 ]
174
+
172
175
pd.Series([' foo 123' , ' bar baz' , np.nan]).str.replace(pat, repl)
173
176
174
177
# Using regex groups
175
178
pat = r " ( ?P<one> \w + ) ( ?P<two> \w + ) ( ?P<three> \w + ) "
176
- repl = lambda m : m.group(' two' ).swapcase() # noqa: E731
179
+
180
+ def repl (m ):
181
+ return m.group(' two' ).swapcase()
182
+
177
183
pd.Series([' Foo Bar Baz' , np.nan]).str.replace(pat, repl)
178
184
179
185
.. versionadded :: 0.20.0
@@ -191,12 +197,11 @@ compiled regular expression object.
191
197
Including a ``flags `` argument when calling ``replace `` with a compiled
192
198
regular expression object will raise a ``ValueError ``.
193
199
194
- .. ipython ::
200
+ .. ipython :: ipython
201
+ :verbatim:
195
202
196
- @verbatim
197
203
In [1]: s3.str.replace(regex_pat, 'XX-XX ', flags=re.IGNORECASE)
198
- ---------------------------------------------------------------------------
199
- ValueError: case and flags cannot be set when pat is a compiled regex
204
+ Out[1]: ValueError: case and flags cannot be set when pat is a compiled regex
200
205
201
206
.. _text.concatenate :
202
207
You can’t perform that action at this time.
0 commit comments