Skip to content

Commit e869e0d

Browse files
committed
Added example for bag groupby and foldby as requested in issue 46
1 parent 092e8c4 commit e869e0d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bag.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@
138138
"b.count().compute() # Count total number of records"
139139
]
140140
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": null,
144+
"metadata": {},
145+
"outputs": [],
146+
"source": [
147+
"(b.groupby(lambda record:record[\"occupation\"]).map(lambda kv: ( kv[0], len(kv[1]))).compute()[:10]) # using groupby to count people in each occupation"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"metadata": {},
154+
"outputs": [],
155+
"source": [
156+
"city_counts = b.foldby(key = lambda record:record[\"address\"][\"city\"], binop = lambda acc, record:acc + 1, initial = 0 ) # using foldby to count people living by city\n",
157+
"city_counts.take(10)"
158+
]
159+
},
141160
{
142161
"cell_type": "markdown",
143162
"metadata": {},

0 commit comments

Comments
 (0)