Skip to content

Commit

Permalink
add bike analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzM00 committed Oct 28, 2024
1 parent def5ca9 commit 61c1ed3
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 0 deletions.
191 changes: 191 additions & 0 deletions notebooks/analyze_bikes.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import holidays\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"\n",
"sns.set_theme(style=\"ticks\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bikes = pd.read_parquet(\"../data/bikes.parquet\")\n",
"bikes.info()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bikes.describe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.lineplot(data=bikes)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.lineplot(bikes.query(\"date >= '2018' & date <= '2019'\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bikes[bikes.bike_count.isna()]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bikes = bikes.interpolate()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.lineplot(bikes.loc[\"2023\":\"2023-12-31\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bikes = bikes.assign(\n",
" year=bikes.index.year,\n",
" month=bikes.index.month,\n",
" day=bikes.index.day,\n",
" weekday=bikes.index.weekday,\n",
" quarter=bikes.index.quarter,\n",
" week=bikes.index.dayofweek,\n",
" is_corona=bikes.index.isin(pd.date_range(\"2020-03-15\", \"2021-05-15\")),\n",
")\n",
"bikes.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.boxplot(bikes, x=\"month\", y=\"bike_count\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.boxplot(bikes, x=\"quarter\", y=\"bike_count\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.boxplot(bikes, x=\"week\", y=\"bike_count\", hue=\"is_corona\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.boxplot(bikes, x=\"quarter\", y=\"bike_count\", hue=\"is_corona\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"german_holidays = holidays.Germany(years=range(2018, 2024), subdiv=\"BW\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# add them to bikes\n",
"bikes[\"is_holiday\"] = bikes.index.isin(german_holidays)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sns.catplot(bikes, x=\"is_holiday\", y=\"bike_count\", kind=\"box\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ requires-python = ">=3.10"
dependencies = [
"click>=8.1.7",
"dvc>=3.55.2",
"holidays>=0.59",
"loguru>=0.7.2",
"matplotlib>=3.9.2",
"numpy>=2.0.2",
Expand Down
14 changes: 14 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61c1ed3

Please sign in to comment.