Skip to content

Commit 10ed42a

Browse files
author
Dennis Bakhuis
committed
small typo
1 parent ba97c84 commit 10ed42a

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

‎B_Pandas_tips/3 - transform results back to original dataframe size.ipynb‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"metadata": {},
66
"source": [
77
"# Pandas tip #3: Transform .groupby() result back into original DataFrame\n",
8-
"Sometime you need to get a statistic from a subgroup in a dataset and require this statistic to be in the original dataset. Previously I did this in multiple steps but this can also be achieved by a lesser known method in Pandas: `.transform()`.\n",
8+
"Sometime you need to get a statistic from a subgroup in a dataset and require this statistic to be in the original dataset. Previously I did this in multiple steps but this can also be achieved with a lesser known method in Pandas: `.transform()`.\n",
99
"\n",
10-
"The `.transform()` method acts very similarly to the `.apply()` function and is especially powerfull after a `.groupby()`. It does a sort of `.apply()` on the groupby result and then transforms this into the length of the original DataFrame. Lets have a look a some artificial data:"
10+
"The `.transform()` method acts very similarly to the `.apply()` function and is especially powerful after a `.groupby()`. It does a sort of `.apply()` on the groupby result and then transforms this into the length of the original DataFrame. Lets have a look a some artificial data:"
1111
]
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": 15,
15+
"execution_count": 33,
1616
"metadata": {},
1717
"outputs": [],
1818
"source": [
@@ -42,7 +42,7 @@
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": 17,
45+
"execution_count": 34,
4646
"metadata": {},
4747
"outputs": [
4848
{
@@ -55,7 +55,7 @@
5555
"Name: group, dtype: int64"
5656
]
5757
},
58-
"execution_count": 17,
58+
"execution_count": 34,
5959
"metadata": {},
6060
"output_type": "execute_result"
6161
}
@@ -74,7 +74,7 @@
7474
},
7575
{
7676
"cell_type": "code",
77-
"execution_count": 22,
77+
"execution_count": 35,
7878
"metadata": {},
7979
"outputs": [
8080
{
@@ -88,7 +88,7 @@
8888
"Name: spend_money, dtype: float64"
8989
]
9090
},
91-
"execution_count": 22,
91+
"execution_count": 35,
9292
"metadata": {},
9393
"output_type": "execute_result"
9494
}
@@ -109,7 +109,7 @@
109109
},
110110
{
111111
"cell_type": "code",
112-
"execution_count": 25,
112+
"execution_count": 36,
113113
"metadata": {},
114114
"outputs": [
115115
{
@@ -239,7 +239,7 @@
239239
"[100 rows x 4 columns]"
240240
]
241241
},
242-
"execution_count": 25,
242+
"execution_count": 36,
243243
"metadata": {},
244244
"output_type": "execute_result"
245245
}
@@ -261,7 +261,7 @@
261261
},
262262
{
263263
"cell_type": "code",
264-
"execution_count": 29,
264+
"execution_count": 37,
265265
"metadata": {},
266266
"outputs": [
267267
{
@@ -270,7 +270,7 @@
270270
"29.8"
271271
]
272272
},
273-
"execution_count": 29,
273+
"execution_count": 37,
274274
"metadata": {},
275275
"output_type": "execute_result"
276276
}
@@ -292,7 +292,7 @@
292292
},
293293
{
294294
"cell_type": "code",
295-
"execution_count": 31,
295+
"execution_count": 38,
296296
"metadata": {},
297297
"outputs": [
298298
{
@@ -320,7 +320,7 @@
320320
" <th>group</th>\n",
321321
" <th>spend_money</th>\n",
322322
" <th>group_mean</th>\n",
323-
" <th>2nd_place</th>\n",
323+
" <th>2nd_lowest</th>\n",
324324
" </tr>\n",
325325
" </thead>\n",
326326
" <tbody>\n",
@@ -418,23 +418,23 @@
418418
"</div>"
419419
],
420420
"text/plain": [
421-
" id group spend_money group_mean 2nd_place\n",
422-
"0 0 A 25.01 504.031724 29.80\n",
423-
"1 1 C 244.89 530.030909 111.55\n",
424-
"2 2 B 736.47 506.783600 94.33\n",
425-
"3 3 A 590.49 504.031724 29.80\n",
426-
"4 4 A 29.80 504.031724 29.80\n",
427-
".. .. ... ... ... ...\n",
428-
"95 95 C 800.59 530.030909 111.55\n",
429-
"96 96 A 248.66 504.031724 29.80\n",
430-
"97 97 B 536.29 506.783600 94.33\n",
431-
"98 98 B 421.88 506.783600 94.33\n",
432-
"99 99 C 462.63 530.030909 111.55\n",
421+
" id group spend_money group_mean 2nd_lowest\n",
422+
"0 0 A 25.01 504.031724 29.80\n",
423+
"1 1 C 244.89 530.030909 111.55\n",
424+
"2 2 B 736.47 506.783600 94.33\n",
425+
"3 3 A 590.49 504.031724 29.80\n",
426+
"4 4 A 29.80 504.031724 29.80\n",
427+
".. .. ... ... ... ...\n",
428+
"95 95 C 800.59 530.030909 111.55\n",
429+
"96 96 A 248.66 504.031724 29.80\n",
430+
"97 97 B 536.29 506.783600 94.33\n",
431+
"98 98 B 421.88 506.783600 94.33\n",
432+
"99 99 C 462.63 530.030909 111.55\n",
433433
"\n",
434434
"[100 rows x 5 columns]"
435435
]
436436
},
437-
"execution_count": 31,
437+
"execution_count": 38,
438438
"metadata": {},
439439
"output_type": "execute_result"
440440
}
@@ -446,7 +446,7 @@
446446
" else:\n",
447447
" return None\n",
448448
"\n",
449-
"df['2nd_place'] = (df\n",
449+
"df['2nd_lowest'] = (df\n",
450450
" .groupby('group')['spend_money']\n",
451451
" .transform(second_from_group)\n",
452452
")\n",

0 commit comments

Comments
 (0)