Skip to content

Commit

Permalink
Updates to Pandas using assign
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbois committed Jun 13, 2024
1 parent 4209d52 commit 159007e
Show file tree
Hide file tree
Showing 113 changed files with 4,018 additions and 3,781 deletions.
1,716 changes: 858 additions & 858 deletions 2024/_sources/lessons/l16_intro_to_pandas.ipynb.txt

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions 2024/_sources/lessons/l17_split_apply_combine.ipynb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
],
"source": [
"df = pd.read_csv('data/gfmt_sleep.csv', na_values='*')\n",
"df['insomnia'] = df['sci'] <= 16\n",
"df = df.assign(insomnia=df['sci'] <= 16)\n",
"\n",
"# Take a look\n",
"df.head()"
Expand Down Expand Up @@ -325,7 +325,7 @@
{
"data": {
"text/plain": [
"<pandas.core.groupby.generic.DataFrameGroupBy object at 0x1208c3d90>"
"<pandas.core.groupby.generic.DataFrameGroupBy object at 0x138635d10>"
]
},
"execution_count": 3,
Expand Down Expand Up @@ -1050,7 +1050,9 @@
}
],
"source": [
"df['rank grouped by insomnia'] = grouped['percent correct'].rank(method='first')\n",
"df = df.assign(\n",
" **{\"rank grouped by insomnia\": grouped[\"percent correct\"].rank(method=\"first\")}\n",
")\n",
"\n",
"# Take a look\n",
"df.head()"
Expand Down Expand Up @@ -1351,7 +1353,7 @@
],
"source": [
"cols = df.columns[(df.columns != 'gender') & (df.columns != 'insomnia')]\n",
"grouped[cols].agg(coeff_of_var).reset_index()"
"df.groupby('insomnia')[cols].agg(coeff_of_var).reset_index()"
]
},
{
Expand Down Expand Up @@ -1589,7 +1591,9 @@
}
],
"source": [
"df['ecdf_y grouped by insomnia'] = grouped['percent correct'].transform(ecdf_y)\n",
"df = df.assign(\n",
" **{\"ecdf_y grouped by insomnia\": grouped[\"percent correct\"].transform(ecdf_y)}\n",
")\n",
"\n",
"# Take a look\n",
"df.head()"
Expand Down
46 changes: 23 additions & 23 deletions 2024/_sources/lessons/l18_plotting.ipynb.txt

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions 2024/_sources/lessons/l19_high_level_plotting.ipynb.txt

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions 2024/_sources/lessons/l20_styling_bokeh.ipynb.txt

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions 2024/_sources/lessons/l28_dashboards.ipynb.txt

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions 2024/_sources/lessons/l29_javascript_for_bokeh.ipynb.txt

Large diffs are not rendered by default.

279 changes: 177 additions & 102 deletions 2024/_sources/lessons/l40_holoviews.ipynb.txt

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions 2024/_sources/lessons/l41_altair.ipynb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"outputs": [],
"source": [
"df = pd.read_csv('data/gfmt_sleep.csv', na_values='*')\n",
"df['insomnia'] = df['sci'] <= 16"
"df = df.assign(insomnia=df['sci'] <= 16)"
]
},
{
Expand All @@ -62,23 +62,23 @@
"text/html": [
"\n",
"<style>\n",
" #altair-viz-531a315b76fc474193d0ff42c9cf0466.vega-embed {\n",
" #altair-viz-6ff02af174f14bd3a7633c42c0af0af5.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-531a315b76fc474193d0ff42c9cf0466.vega-embed details,\n",
" #altair-viz-531a315b76fc474193d0ff42c9cf0466.vega-embed details summary {\n",
" #altair-viz-6ff02af174f14bd3a7633c42c0af0af5.vega-embed details,\n",
" #altair-viz-6ff02af174f14bd3a7633c42c0af0af5.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-531a315b76fc474193d0ff42c9cf0466\"></div>\n",
"<div id=\"altair-viz-6ff02af174f14bd3a7633c42c0af0af5\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-531a315b76fc474193d0ff42c9cf0466\") {\n",
" outputDiv = document.getElementById(\"altair-viz-531a315b76fc474193d0ff42c9cf0466\");\n",
" if (outputDiv.id !== \"altair-viz-6ff02af174f14bd3a7633c42c0af0af5\") {\n",
" outputDiv = document.getElementById(\"altair-viz-6ff02af174f14bd3a7633c42c0af0af5\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
Expand Down Expand Up @@ -191,23 +191,23 @@
"text/html": [
"\n",
"<style>\n",
" #altair-viz-99eef1a42026412790750797865974d6.vega-embed {\n",
" #altair-viz-2b527c3e3db5460cba8c31b3b4af9fd9.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-99eef1a42026412790750797865974d6.vega-embed details,\n",
" #altair-viz-99eef1a42026412790750797865974d6.vega-embed details summary {\n",
" #altair-viz-2b527c3e3db5460cba8c31b3b4af9fd9.vega-embed details,\n",
" #altair-viz-2b527c3e3db5460cba8c31b3b4af9fd9.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-99eef1a42026412790750797865974d6\"></div>\n",
"<div id=\"altair-viz-2b527c3e3db5460cba8c31b3b4af9fd9\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-99eef1a42026412790750797865974d6\") {\n",
" outputDiv = document.getElementById(\"altair-viz-99eef1a42026412790750797865974d6\");\n",
" if (outputDiv.id !== \"altair-viz-2b527c3e3db5460cba8c31b3b4af9fd9\") {\n",
" outputDiv = document.getElementById(\"altair-viz-2b527c3e3db5460cba8c31b3b4af9fd9\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
Expand Down Expand Up @@ -313,23 +313,23 @@
"text/html": [
"\n",
"<style>\n",
" #altair-viz-b85b3020391e40b6b8aeb4ccc3a3cc34.vega-embed {\n",
" #altair-viz-2f2cfdf4162b441094be52da05fa03ff.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-b85b3020391e40b6b8aeb4ccc3a3cc34.vega-embed details,\n",
" #altair-viz-b85b3020391e40b6b8aeb4ccc3a3cc34.vega-embed details summary {\n",
" #altair-viz-2f2cfdf4162b441094be52da05fa03ff.vega-embed details,\n",
" #altair-viz-2f2cfdf4162b441094be52da05fa03ff.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-b85b3020391e40b6b8aeb4ccc3a3cc34\"></div>\n",
"<div id=\"altair-viz-2f2cfdf4162b441094be52da05fa03ff\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-b85b3020391e40b6b8aeb4ccc3a3cc34\") {\n",
" outputDiv = document.getElementById(\"altair-viz-b85b3020391e40b6b8aeb4ccc3a3cc34\");\n",
" if (outputDiv.id !== \"altair-viz-2f2cfdf4162b441094be52da05fa03ff\") {\n",
" outputDiv = document.getElementById(\"altair-viz-2f2cfdf4162b441094be52da05fa03ff\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
Expand Down Expand Up @@ -414,23 +414,23 @@
"text/html": [
"\n",
"<style>\n",
" #altair-viz-1c8e00fbed6a494c8c4cefc6315c901a.vega-embed {\n",
" #altair-viz-7ddb269646d94fe6bc1fe95c0adf6771.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-1c8e00fbed6a494c8c4cefc6315c901a.vega-embed details,\n",
" #altair-viz-1c8e00fbed6a494c8c4cefc6315c901a.vega-embed details summary {\n",
" #altair-viz-7ddb269646d94fe6bc1fe95c0adf6771.vega-embed details,\n",
" #altair-viz-7ddb269646d94fe6bc1fe95c0adf6771.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-1c8e00fbed6a494c8c4cefc6315c901a\"></div>\n",
"<div id=\"altair-viz-7ddb269646d94fe6bc1fe95c0adf6771\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-1c8e00fbed6a494c8c4cefc6315c901a\") {\n",
" outputDiv = document.getElementById(\"altair-viz-1c8e00fbed6a494c8c4cefc6315c901a\");\n",
" if (outputDiv.id !== \"altair-viz-7ddb269646d94fe6bc1fe95c0adf6771\") {\n",
" outputDiv = document.getElementById(\"altair-viz-7ddb269646d94fe6bc1fe95c0adf6771\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
Expand Down Expand Up @@ -520,23 +520,23 @@
"text/html": [
"\n",
"<style>\n",
" #altair-viz-f9a4db84d9514548ab292850592e73fa.vega-embed {\n",
" #altair-viz-450267754f604feea9407ec947bc9ca9.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-f9a4db84d9514548ab292850592e73fa.vega-embed details,\n",
" #altair-viz-f9a4db84d9514548ab292850592e73fa.vega-embed details summary {\n",
" #altair-viz-450267754f604feea9407ec947bc9ca9.vega-embed details,\n",
" #altair-viz-450267754f604feea9407ec947bc9ca9.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-f9a4db84d9514548ab292850592e73fa\"></div>\n",
"<div id=\"altair-viz-450267754f604feea9407ec947bc9ca9\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-f9a4db84d9514548ab292850592e73fa\") {\n",
" outputDiv = document.getElementById(\"altair-viz-f9a4db84d9514548ab292850592e73fa\");\n",
" if (outputDiv.id !== \"altair-viz-450267754f604feea9407ec947bc9ca9\") {\n",
" outputDiv = document.getElementById(\"altair-viz-450267754f604feea9407ec947bc9ca9\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
Expand Down Expand Up @@ -629,23 +629,23 @@
"text/html": [
"\n",
"<style>\n",
" #altair-viz-28ef80d44adb4a0989cbcb811d27c9f7.vega-embed {\n",
" #altair-viz-36f7d4b47d1a457a936742c54e5b7c38.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-28ef80d44adb4a0989cbcb811d27c9f7.vega-embed details,\n",
" #altair-viz-28ef80d44adb4a0989cbcb811d27c9f7.vega-embed details summary {\n",
" #altair-viz-36f7d4b47d1a457a936742c54e5b7c38.vega-embed details,\n",
" #altair-viz-36f7d4b47d1a457a936742c54e5b7c38.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-28ef80d44adb4a0989cbcb811d27c9f7\"></div>\n",
"<div id=\"altair-viz-36f7d4b47d1a457a936742c54e5b7c38\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-28ef80d44adb4a0989cbcb811d27c9f7\") {\n",
" outputDiv = document.getElementById(\"altair-viz-28ef80d44adb4a0989cbcb811d27c9f7\");\n",
" if (outputDiv.id !== \"altair-viz-36f7d4b47d1a457a936742c54e5b7c38\") {\n",
" outputDiv = document.getElementById(\"altair-viz-36f7d4b47d1a457a936742c54e5b7c38\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
Expand Down Expand Up @@ -730,23 +730,23 @@
"text/html": [
"\n",
"<style>\n",
" #altair-viz-a82ad945eddd4df5a383a71a0cc0dc87.vega-embed {\n",
" #altair-viz-41a41e709c4e4ddf988af6c307adad14.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-a82ad945eddd4df5a383a71a0cc0dc87.vega-embed details,\n",
" #altair-viz-a82ad945eddd4df5a383a71a0cc0dc87.vega-embed details summary {\n",
" #altair-viz-41a41e709c4e4ddf988af6c307adad14.vega-embed details,\n",
" #altair-viz-41a41e709c4e4ddf988af6c307adad14.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-a82ad945eddd4df5a383a71a0cc0dc87\"></div>\n",
"<div id=\"altair-viz-41a41e709c4e4ddf988af6c307adad14\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-a82ad945eddd4df5a383a71a0cc0dc87\") {\n",
" outputDiv = document.getElementById(\"altair-viz-a82ad945eddd4df5a383a71a0cc0dc87\");\n",
" if (outputDiv.id !== \"altair-viz-41a41e709c4e4ddf988af6c307adad14\") {\n",
" outputDiv = document.getElementById(\"altair-viz-41a41e709c4e4ddf988af6c307adad14\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
Expand Down
Loading

0 comments on commit 159007e

Please sign in to comment.