Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zack C Atus Analysis #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
450 changes: 450 additions & 0 deletions American Time Use Analysis.ipynb

Large diffs are not rendered by default.

88 changes: 16 additions & 72 deletions Starting Point.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"import pandas as pd\n",
"import re"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand All @@ -23,9 +20,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"import matplotlib.pyplot as plt"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand All @@ -34,9 +29,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand All @@ -45,10 +38,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"summary = pd.read_csv(\"atusdata/atussum_2013/atussum_2013.dat\")\n",
"summary.info()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -299,10 +289,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"adults_crit = (summary.TEAGE >= 18)\n",
"no_children_crit = (summary.TRCHILDNUM == 0)"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand All @@ -311,10 +298,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"adults_with_no_children = summary[adults_crit & no_children_crit]\n",
"adults_with_no_children.info()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
Expand All @@ -335,11 +319,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"data = adults_with_no_children[['TUFINLWGT', 't120303']]\n",
"data = data.rename(columns={\"TUFINLWGT\": \"weight\", \"t120303\": \"minutes\"})\n",
"data.head()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -402,9 +382,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"data['weighted_minutes'] = data.weight * data.minutes"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -484,9 +462,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"data.weighted_minutes.sum() / data.weight.sum() / 60"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
Expand All @@ -504,14 +480,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"def average_minutes(data, activity_code):\n",
" activity_col = \"t{}\".format(activity_code)\n",
" data = data[['TUFINLWGT', activity_col]]\n",
" data = data.rename(columns={\"TUFINLWGT\": \"weight\", activity_col: \"minutes\"})\n",
" data['weighted_minutes'] = data.weight * data.minutes\n",
" return data.weighted_minutes.sum() / data.weight.sum()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand All @@ -520,11 +489,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"sleeping = average_minutes(adults_with_no_children, \"010101\")\n",
"sleepless = average_minutes(adults_with_no_children, \"010102\")\n",
"(sleeping + sleepless) / 60"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
Expand All @@ -542,12 +507,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"def activity_columns(data, activity_code):\n",
" \"\"\"For the activity code given, return all columns that fall under that activity.\"\"\"\n",
" col_prefix = \"t{}\".format(activity_code)\n",
" return [column for column in data.columns if re.match(col_prefix, column)]"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand All @@ -556,9 +516,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"activity_columns(summary, \"0101\")"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
Expand All @@ -576,17 +534,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"def average_minutes2(data, activity_code):\n",
" cols = activity_columns(data, activity_code)\n",
" activity_data = data[cols]\n",
" activity_sums = activity_data.sum(axis=1)\n",
" data = data[['TUFINLWGT']]\n",
" data['minutes'] = activity_sums\n",
" data = data.rename(columns={\"TUFINLWGT\": \"weight\"})\n",
" data['weighted_minutes'] = data.weight * data.minutes\n",
" return data.weighted_minutes.sum() / data.weight.sum()"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -698,9 +646,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"group = summary.groupby([\"TEAGE\", \"TESEX\", \"TRCHILDNUM\"])"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
Expand All @@ -709,9 +655,7 @@
{
"cell_type": "code",
"collapsed": false,
"input": [
"group.mean().xs(15).xs(1)"
],
"input": [],
"language": "python",
"metadata": {},
"outputs": [
Expand Down
Loading