Skip to content

Commit

Permalink
exemples.ipynb: Add DataFrame.groupby.expanding.apply
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Aug 24, 2020
1 parent 83a4d01 commit a59b6b1
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,54 @@
"res.equals(res_parallel)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# DataFrame.groupby.expanding.apply"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_size = int(1e6)\n",
"df = pd.DataFrame(dict(a=np.random.randint(1, 300, df_size),\n",
" b=np.random.rand(df_size)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def func(x):\n",
" return x.iloc[0] + x.iloc[1] ** 2 + x.iloc[2] ** 3 + x.iloc[3] ** 4"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"res = df.groupby('a').b.expanding(4).apply(func, raw=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"res_parallel = df.groupby('a').b.expanding(4).parallel_apply(func, raw=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit a59b6b1

Please sign in to comment.