ogd-at-lab/notebooks/mobility.ipynb

128 wiersze
3.2 KiB
Plaintext
Czysty Zwykły widok Historia

2021-02-10 11:45:33 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Urban Mobility\n",
"\n",
"[![Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/anitagraser/ogd-at-lab/main?urlpath=lab/tree/notebooks/mobility.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import hvplot.pandas\n",
"from utils.dataaccess import get_uber_movement_gdf"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Uber Movement\n",
"\n",
"Source: https://movement.uber.com/explore/vienna/travel-times\n",
"\n",
"© 2021 Copyright Uber Technologies. Data made available under the [Creative Commons, Attribution Non-Commercial](https://creativecommons.org/licenses/by-nc/3.0/us/) license"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gdf = get_uber_movement_gdf()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2021-02-10 17:37:44 +00:00
"def plot_uber(source_id, attribute_col, month, *args, **kwargs):\n",
" return ( gdf[(gdf.sourceid==source_id) & (gdf.month==month)].dropna(subset=[attribute_col]).hvplot(\n",
" geo=True, tiles='OSM', c=attribute_col, title=f'{attribute_col.title()} - Month: 2020-{month}', *args, **kwargs) * \n",
" gdf[gdf.index==source_id].hvplot(geo=True).opts(active_tools=['wheel_zoom']))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2021-02-10 11:45:33 +00:00
"COL = 'mean_travel_time'\n",
2021-02-10 17:37:44 +00:00
"ID = 1\n",
"plot_uber(ID, COL, 1) + plot_uber(ID, COL, 2) + plot_uber(ID, COL, 3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"jan = gdf[gdf.month==1].groupby('sourceid').count()\n",
"feb = gdf[gdf.month==2].groupby('sourceid').count()\n",
"mar = gdf[gdf.month==3].groupby('sourceid').count() "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"joined = feb.join(mar, lsuffix='_feb', rsuffix='_mar')\n",
"diff = joined[f'{COL}_mar'] - joined[f'{COL}_feb'] \n",
"diff.hvplot.hist(title='Histogram of destination area counts (March 2020 - Feb 2020)')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"joined = jan.join(feb, lsuffix='_jan', rsuffix='_feb')\n",
"diff = joined[f'{COL}_feb'] - joined[f'{COL}_jan'] \n",
"diff.hvplot.hist(title='Histogram of destination area counts (Feb 2020 - Jan 2020)')"
2021-02-10 11:45:33 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.7.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}