Skip to content

Commit c6309de

Browse files
FHaasePingviinituutti
authored andcommitted
Fix PEP-8 issues in basics.rst (pandas-dev#23910)
Signed-off-by: Fabian Haase <[email protected]>
1 parent bab6e6c commit c6309de

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

doc/source/basics.rst

+30-26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
import numpy as np
77
import pandas as pd
8+
89
np.set_printoptions(precision=4, suppress=True)
910
pd.options.display.max_rows = 15
1011
@@ -173,8 +174,9 @@ Furthermore you can align a level of a MultiIndexed DataFrame with a Series.
173174
.. ipython:: python
174175
175176
dfmi = df.copy()
176-
dfmi.index = pd.MultiIndex.from_tuples([
177-
(1, 'a'), (1, 'b'), (1, 'c'), (2, 'a')], names=['first', 'second'])
177+
dfmi.index = pd.MultiIndex.from_tuples([(1, 'a'), (1, 'b'),
178+
(1, 'c'), (2, 'a')],
179+
names=['first', 'second'])
178180
dfmi.sub(column, axis=0, level='second')
179181
180182
With Panel, describing the matching behavior is a bit more difficult, so
@@ -565,8 +567,8 @@ course):
565567
series = pd.Series(np.random.randn(1000))
566568
series[::2] = np.nan
567569
series.describe()
568-
frame = pd.DataFrame(
569-
np.random.randn(1000, 5), columns=['a', 'b', 'c', 'd', 'e'])
570+
frame = pd.DataFrame(np.random.randn(1000, 5),
571+
columns=['a', 'b', 'c', 'd', 'e'])
570572
frame.iloc[::2] = np.nan
571573
frame.describe()
572574
@@ -1088,8 +1090,10 @@ a single value and returning a single value. For example:
10881090
.. ipython:: python
10891091
10901092
df4
1093+
10911094
def f(x):
1092-
len(str(x))
1095+
return len(str(x))
1096+
10931097
df4['one'].map(f)
10941098
df4.applymap(f)
10951099
@@ -1433,10 +1437,8 @@ Thus, for example, iterating over a DataFrame gives you the column names:
14331437

14341438
.. ipython:: python
14351439
1436-
df = pd.DataFrame({
1437-
'col1': np.random.randn(3),
1438-
'col2': np.random.randn(3)},
1439-
index=['a', 'b', 'c'])
1440+
df = pd.DataFrame({'col1': np.random.randn(3),
1441+
'col2': np.random.randn(3)}, index=['a', 'b', 'c'])
14401442
14411443
for col in df:
14421444
print(col)
@@ -1556,7 +1558,7 @@ For instance, a contrived way to transpose the DataFrame would be:
15561558
print(df2)
15571559
print(df2.T)
15581560
1559-
df2_t = pd.DataFrame(dict((idx, values) for idx, values in df2.iterrows()))
1561+
df2_t = pd.DataFrame({idx: values for idx, values in df2.iterrows()})
15601562
print(df2_t)
15611563
15621564
itertuples
@@ -1732,8 +1734,9 @@ to use to determine the sorted order.
17321734

17331735
.. ipython:: python
17341736
1735-
df1 = pd.DataFrame({
1736-
'one': [2, 1, 1, 1], 'two': [1, 3, 2, 4], 'three': [5, 4, 3, 2]})
1737+
df1 = pd.DataFrame({'one': [2, 1, 1, 1],
1738+
'two': [1, 3, 2, 4],
1739+
'three': [5, 4, 3, 2]})
17371740
df1.sort_values(by='two')
17381741
17391742
The ``by`` parameter can take a list of column names, e.g.:
@@ -1843,8 +1846,9 @@ all levels to ``by``.
18431846

18441847
.. ipython:: python
18451848
1846-
df1.columns = pd.MultiIndex.from_tuples([
1847-
('a', 'one'), ('a', 'two'), ('b', 'three')])
1849+
df1.columns = pd.MultiIndex.from_tuples([('a', 'one'),
1850+
('a', 'two'),
1851+
('b', 'three')])
18481852
df1.sort_values(by=('a', 'two'))
18491853
18501854
@@ -1894,13 +1898,13 @@ with the data type of each column.
18941898

18951899
.. ipython:: python
18961900
1897-
dft = pd.DataFrame(dict(A=np.random.rand(3),
1898-
B=1,
1899-
C='foo',
1900-
D=pd.Timestamp('20010102'),
1901-
E=pd.Series([1.0] * 3).astype('float32'),
1902-
F=False,
1903-
G=pd.Series([1] * 3, dtype='int8')))
1901+
dft = pd.DataFrame({'A': np.random.rand(3),
1902+
'B': 1,
1903+
'C': 'foo',
1904+
'D': pd.Timestamp('20010102'),
1905+
'E': pd.Series([1.0] * 3).astype('float32'),
1906+
'F': False,
1907+
'G': pd.Series([1] * 3, dtype='int8')})
19041908
dft
19051909
dft.dtypes
19061910
@@ -1939,10 +1943,10 @@ different numeric dtypes will **NOT** be combined. The following example will gi
19391943
df1 = pd.DataFrame(np.random.randn(8, 1), columns=['A'], dtype='float32')
19401944
df1
19411945
df1.dtypes
1942-
df2 = pd.DataFrame(dict(A=pd.Series(np.random.randn(8), dtype='float16'),
1943-
B=pd.Series(np.random.randn(8)),
1944-
C=pd.Series(np.array(np.random.randn(8),
1945-
dtype='uint8'))))
1946+
df2 = pd.DataFrame({'A': pd.Series(np.random.randn(8), dtype='float16'),
1947+
'B': pd.Series(np.random.randn(8)),
1948+
'C': pd.Series(np.array(np.random.randn(8),
1949+
dtype='uint8'))})
19461950
df2
19471951
df2.dtypes
19481952
@@ -2057,7 +2061,7 @@ to the correct type.
20572061
df = pd.DataFrame([[1, 2],
20582062
['a', 'b'],
20592063
[datetime.datetime(2016, 3, 2),
2060-
datetime.datetime(2016, 3, 2)]])
2064+
datetime.datetime(2016, 3, 2)]])
20612065
df = df.T
20622066
df
20632067
df.dtypes

0 commit comments

Comments
 (0)