Created
February 17, 2017 16:28
-
-
Save EthanRosenthal/1894037da46978767ce2953e2c7aa3d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"def full_time(df):\n", | |
" \n", | |
" # Get all the times\n", | |
" bins = df.daytime.unique()\n", | |
" bins.sort()\n", | |
" first = np.where(bins == '09:00:00')[0][0]\n", | |
" last = np.where(bins == '10:00:00')[0][0]\n", | |
" bins = bins[first:last]\n", | |
" n_bins = bins.shape[0]\n", | |
"\n", | |
" # Ignore weekends, just grab between 9-10\n", | |
" # Group by calendar date\n", | |
" groups = (df[(~np.in1d(df.index.dayofweek, [5, 6]))\n", | |
" & (df.daytime.isin(bins))]\n", | |
" .groupby('cal_date'))\n", | |
"\n", | |
" all_times = 0\n", | |
" zero_times = 0\n", | |
" for i, group in groups:\n", | |
" these_zero_times = group[group.available_docks == 0]\n", | |
" all_times += n_bins \n", | |
" if not these_zero_times.empty:\n", | |
" min_time = these_zero_times.daytime.min()\n", | |
" initial_zero = np.where(bins == min_time)[0].min()\n", | |
" zero_times += n_bins - initial_zero\n", | |
" return zero_times / all_times" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Old office (Howard) full station probability = 20.13%\n", | |
"New office (Macdougal) full station probability = 36.87%\n" | |
] | |
} | |
], | |
"source": [ | |
"mac_prob = full_time(macdougal) * 100\n", | |
"how_prob = full_time(howard) * 100\n", | |
"\n", | |
"print('Old office (Howard) full station probability = {:4.2f}%'.format(how_prob))\n", | |
"print('New office (Macdougal) full station probability = {:4.2f}%'.format(mac_prob))" | |
] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python [Root]", | |
"language": "python", | |
"name": "Python [Root]" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment