Skip to content

Commit d51ad4d

Browse files
committed
DOC: format Excel comparison code samples with black
Used [blacken-docs](https://github.com/asottile/blacken-docs).
1 parent fad7ddd commit d51ad4d

File tree

1 file changed

+55
-15
lines changed

1 file changed

+55
-15
lines changed

doc/source/getting_started/comparison/comparison_with_excel.rst

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ General terminology translation
3535
~~~~~~~~~~~~~
3636

3737
A ``DataFrame`` in pandas is analogous to an Excel worksheet. While an Excel worksheet can contain
38-
multiple worksheets, pandas ``DataFrame``s exist independently.
38+
multiple worksheets, pandas ``DataFrame``\s exist independently.
3939

4040
``Series``
4141
~~~~~~~~~~
@@ -75,11 +75,13 @@ This can be achieved by creating a series and assigning it to the desired cells.
7575

7676
.. ipython:: python
7777
78-
df = pd.DataFrame({'AAA': [1] * 8, 'BBB': list(range(0, 8))}); df
78+
df = pd.DataFrame({"AAA": [1] * 8, "BBB": list(range(0, 8))})
79+
df
7980
80-
series = list(range(1, 5)); series
81+
series = list(range(1, 5))
82+
series
8183
82-
df.iloc[2:(5+1)].AAA = series
84+
df.iloc[2 : (5 + 1)].AAA = series
8385
8486
df
8587
@@ -106,7 +108,13 @@ pandas.
106108

107109
.. ipython:: python
108110
109-
df = pd.DataFrame({"class": ['A', 'A', 'A', 'B', 'C', 'D'], "student_count": [42, 35, 42, 50, 47, 45], "all_pass": ["Yes", "Yes", "Yes", "No", "No", "Yes"]})
111+
df = pd.DataFrame(
112+
{
113+
"class": ["A", "A", "A", "B", "C", "D"],
114+
"student_count": [42, 35, 42, 50, 47, 45],
115+
"all_pass": ["Yes", "Yes", "Yes", "No", "No", "Yes"],
116+
}
117+
)
110118
111119
df.drop_duplicates()
112120
@@ -128,12 +136,16 @@ each class.
128136

129137
.. ipython:: python
130138
131-
df["girls_count"] = [21, 12, 21, 31, 23, 17]; df
139+
df["girls_count"] = [21, 12, 21, 31, 23, 17]
140+
df
141+
132142
133143
def get_count(row):
134144
return row["student_count"] - row["girls_count"]
135145
136-
df["boys_count"] = df.apply(get_count, axis = 1); df
146+
147+
df["boys_count"] = df.apply(get_count, axis=1)
148+
df
137149
138150
139151
VLOOKUP
@@ -143,16 +155,43 @@ VLOOKUP
143155
144156
import random
145157
146-
df1 = pd.DataFrame({"keys": [1, 2, 3, 4, 5, 6, 7], "first_names": ["harry", "ron",
147-
"hermione", "rubius", "albus", "severus", "luna"]}); df1
148-
149-
random_names = pd.DataFrame({"surnames": ["hadrid", "malfoy", "lovegood",
150-
"dumbledore", "grindelwald", "granger", "weasly", "riddle", "longbottom",
151-
"snape"], "keys": [ random.randint(1,7) for x in range(0,10) ]})
158+
df1 = pd.DataFrame(
159+
{
160+
"keys": [1, 2, 3, 4, 5, 6, 7],
161+
"first_names": [
162+
"harry",
163+
"ron",
164+
"hermione",
165+
"rubius",
166+
"albus",
167+
"severus",
168+
"luna",
169+
],
170+
}
171+
)
172+
df1
173+
174+
random_names = pd.DataFrame(
175+
{
176+
"surnames": [
177+
"hadrid",
178+
"malfoy",
179+
"lovegood",
180+
"dumbledore",
181+
"grindelwald",
182+
"granger",
183+
"weasly",
184+
"riddle",
185+
"longbottom",
186+
"snape",
187+
],
188+
"keys": [random.randint(1, 7) for x in range(0, 10)],
189+
}
190+
)
152191
153192
random_names
154193
155-
random_names.merge(df1, on="keys", how='left')
194+
random_names.merge(df1, on="keys", how="left")
156195
157196
Adding a row
158197
~~~~~~~~~~~~
@@ -163,7 +202,8 @@ NOTE: If the index already exists, the values in that index will be over written
163202

164203
.. ipython:: python
165204
166-
df1.iloc[7] = [8, "tonks"]; df1
205+
df1.iloc[7] = [8, "tonks"]
206+
df1
167207
168208
169209
Search and Replace

0 commit comments

Comments
 (0)