Skip to content

Commit fbea7ca

Browse files
FHaasePingviinituutti
authored andcommitted
Fix PEP-8 issues in text.rst (pandas-dev#23904)
Signed-off-by: Fabian Haase <[email protected]>
1 parent 84a0eec commit fbea7ca

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

doc/source/text.rst

+21-15
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
77
import numpy as np
88
import pandas as pd
9-
randn = np.random.randn
9+
1010
np.set_printoptions(precision=4, suppress=True)
11-
from pandas.compat import lrange
12-
pd.options.display.max_rows=15
11+
pd.options.display.max_rows = 15
1312
1413
======================
1514
Working with Text Data
@@ -43,8 +42,8 @@ leading or trailing whitespace:
4342

4443
.. ipython:: python
4544
46-
df = pd.DataFrame(randn(3, 2), columns=[' Column A ', ' Column B '],
47-
index=range(3))
45+
df = pd.DataFrame(np.random.randn(3, 2),
46+
columns=[' Column A ', ' Column B '], index=range(3))
4847
df
4948
5049
Since ``df.columns`` is an Index object, we can use the ``.str`` accessor
@@ -169,12 +168,18 @@ positional argument (a regex object) and return a string.
169168
170169
# Reverse every lowercase alphabetic word
171170
pat = r'[a-z]+'
172-
repl = lambda m: m.group(0)[::-1]
171+
172+
def repl(m):
173+
return m.group(0)[::-1]
174+
173175
pd.Series(['foo 123', 'bar baz', np.nan]).str.replace(pat, repl)
174176
175177
# Using regex groups
176178
pat = r"(?P<one>\w+) (?P<two>\w+) (?P<three>\w+)"
177-
repl = lambda m: m.group('two').swapcase()
179+
180+
def repl(m):
181+
return m.group('two').swapcase()
182+
178183
pd.Series(['Foo Bar Baz', np.nan]).str.replace(pat, repl)
179184
180185
.. versionadded:: 0.20.0
@@ -216,7 +221,7 @@ The content of a ``Series`` (or ``Index``) can be concatenated:
216221
217222
s = pd.Series(['a', 'b', 'c', 'd'])
218223
s.str.cat(sep=',')
219-
224+
220225
If not specified, the keyword ``sep`` for the separator defaults to the empty string, ``sep=''``:
221226

222227
.. ipython:: python
@@ -239,7 +244,7 @@ The first argument to :meth:`~Series.str.cat` can be a list-like object, provide
239244
.. ipython:: python
240245
241246
s.str.cat(['A', 'B', 'C', 'D'])
242-
247+
243248
Missing values on either side will result in missing values in the result as well, *unless* ``na_rep`` is specified:
244249

245250
.. ipython:: python
@@ -260,7 +265,7 @@ The parameter ``others`` can also be two-dimensional. In this case, the number o
260265
s
261266
d
262267
s.str.cat(d, na_rep='-')
263-
268+
264269
Concatenating a Series and an indexed object into a Series, with alignment
265270
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
266271

@@ -375,7 +380,7 @@ DataFrame with one column per group.
375380

376381
.. ipython:: python
377382
378-
pd.Series(['a1', 'b2', 'c3']).str.extract('([ab])(\d)', expand=False)
383+
pd.Series(['a1', 'b2', 'c3']).str.extract(r'([ab])(\d)', expand=False)
379384
380385
Elements that do not match return a row filled with ``NaN``. Thus, a
381386
Series of messy strings can be "converted" into a like-indexed Series
@@ -388,13 +393,14 @@ Named groups like
388393

389394
.. ipython:: python
390395
391-
pd.Series(['a1', 'b2', 'c3']).str.extract('(?P<letter>[ab])(?P<digit>\d)', expand=False)
396+
pd.Series(['a1', 'b2', 'c3']).str.extract(r'(?P<letter>[ab])(?P<digit>\d)',
397+
expand=False)
392398
393399
and optional groups like
394400

395401
.. ipython:: python
396402
397-
pd.Series(['a1', 'b2', '3']).str.extract('([ab])?(\d)', expand=False)
403+
pd.Series(['a1', 'b2', '3']).str.extract(r'([ab])?(\d)', expand=False)
398404
399405
can also be used. Note that any capture group names in the regular
400406
expression will be used for column names; otherwise capture group
@@ -405,13 +411,13 @@ with one column if ``expand=True``.
405411

406412
.. ipython:: python
407413
408-
pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)', expand=True)
414+
pd.Series(['a1', 'b2', 'c3']).str.extract(r'[ab](\d)', expand=True)
409415
410416
It returns a Series if ``expand=False``.
411417

412418
.. ipython:: python
413419
414-
pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)', expand=False)
420+
pd.Series(['a1', 'b2', 'c3']).str.extract(r'[ab](\d)', expand=False)
415421
416422
Calling on an ``Index`` with a regex with exactly one capture group
417423
returns a ``DataFrame`` with one column if ``expand=True``.

0 commit comments

Comments
 (0)