split tables to confirm hypothesis.
This commit is contained in:
parent
9868fe5fc8
commit
82d1b357b8
1 changed files with 185 additions and 14 deletions
|
@ -275,12 +275,13 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 12,
|
||||||
"id": "00bb9eb1",
|
"id": "00bb9eb1",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# your code here:\n"
|
"# your code here:\n",
|
||||||
|
"event_by_group = df.groupby('group')['event'].sum()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -293,12 +294,13 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": 13,
|
||||||
"id": "db946d0f-8204-43a3-853c-41981a9811f4",
|
"id": "db946d0f-8204-43a3-853c-41981a9811f4",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# your code here:\n"
|
"# your code here:\n",
|
||||||
|
"group_size = df.groupby('group').size()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -313,12 +315,28 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 8,
|
"execution_count": 15,
|
||||||
"id": "13ad4130-2094-4e7a-a416-f0fd6e810413",
|
"id": "13ad4130-2094-4e7a-a416-f0fd6e810413",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"group\n",
|
||||||
|
"Control 4.761905\n",
|
||||||
|
"MedDiet + Nuts 3.322099\n",
|
||||||
|
"MedDiet + VOO 3.856877\n",
|
||||||
|
"dtype: float64"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 15,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"# your code here:\n"
|
"# your code here:\n",
|
||||||
|
"event_by_group / group_size * 100"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -352,12 +370,81 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": 20,
|
||||||
"id": "5ab4e70e-6261-4a26-8ad9-14eae15be09c",
|
"id": "5ab4e70e-6261-4a26-8ad9-14eae15be09c",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th>smoke</th>\n",
|
||||||
|
" <th>Current</th>\n",
|
||||||
|
" <th>Former</th>\n",
|
||||||
|
" <th>Never</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>group</th>\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>Control</th>\n",
|
||||||
|
" <td>13</td>\n",
|
||||||
|
" <td>39</td>\n",
|
||||||
|
" <td>44</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>MedDiet + Nuts</th>\n",
|
||||||
|
" <td>15</td>\n",
|
||||||
|
" <td>20</td>\n",
|
||||||
|
" <td>34</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>MedDiet + VOO</th>\n",
|
||||||
|
" <td>20</td>\n",
|
||||||
|
" <td>29</td>\n",
|
||||||
|
" <td>34</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"smoke Current Former Never\n",
|
||||||
|
"group \n",
|
||||||
|
"Control 13 39 44\n",
|
||||||
|
"MedDiet + Nuts 15 20 34\n",
|
||||||
|
"MedDiet + VOO 20 29 34"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 20,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"# your code here\n"
|
"# your code here\n",
|
||||||
|
"df.pivot_table(index='group', columns='smoke', values='event',aggfunc='sum')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -387,12 +474,96 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": 22,
|
||||||
"id": "196fd111-72bc-4b87-b8fb-293547a8c83d",
|
"id": "196fd111-72bc-4b87-b8fb-293547a8c83d",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead tr th {\n",
|
||||||
|
" text-align: left;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead tr:last-of-type th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th colspan=\"2\" halign=\"left\">mean</th>\n",
|
||||||
|
" <th colspan=\"2\" halign=\"left\">std</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>sex</th>\n",
|
||||||
|
" <th>Female</th>\n",
|
||||||
|
" <th>Male</th>\n",
|
||||||
|
" <th>Female</th>\n",
|
||||||
|
" <th>Male</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>group</th>\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>Control</th>\n",
|
||||||
|
" <td>68.009046</td>\n",
|
||||||
|
" <td>66.400000</td>\n",
|
||||||
|
" <td>5.979313</td>\n",
|
||||||
|
" <td>6.605266</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>MedDiet + Nuts</th>\n",
|
||||||
|
" <td>67.414591</td>\n",
|
||||||
|
" <td>65.822665</td>\n",
|
||||||
|
" <td>5.580050</td>\n",
|
||||||
|
" <td>6.403373</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>MedDiet + VOO</th>\n",
|
||||||
|
" <td>67.668775</td>\n",
|
||||||
|
" <td>66.080045</td>\n",
|
||||||
|
" <td>5.816703</td>\n",
|
||||||
|
" <td>6.621440</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" mean std \n",
|
||||||
|
"sex Female Male Female Male\n",
|
||||||
|
"group \n",
|
||||||
|
"Control 68.009046 66.400000 5.979313 6.605266\n",
|
||||||
|
"MedDiet + Nuts 67.414591 65.822665 5.580050 6.403373\n",
|
||||||
|
"MedDiet + VOO 67.668775 66.080045 5.816703 6.621440"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 22,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"# your code here:\n"
|
"# your code here:\n",
|
||||||
|
"df.pivot_table(index='group', columns='sex', values='age', aggfunc=['mean','std'])\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -412,7 +583,7 @@
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.11.5"
|
"version": "3.13.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue