-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a prototyping document for temporal hierarchical forecasting #127
Some experiments with pandas datetime functions
- Loading branch information
Antoine Carme
committed
May 2, 2020
1 parent
4c25e80
commit 6882c73
Showing
1 changed file
with
189 additions
and
0 deletions.
There are no files selected for viewing
189 changes: 189 additions & 0 deletions
189
notebooks_sandbox/temporal_hierarchy/pandas_datetime_periods.ipynb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import pandas as pd\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"range1 = pd.date_range('1/1/2011', periods=2, freq='H')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"DatetimeIndex(['2011-01-01 00:00:00', '2011-01-01 01:00:00'], dtype='datetime64[ns]', freq='H')" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"range1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"delta_t = range1[1] - range1[0]\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"3600.0" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"delta_t.total_seconds()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 19, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_nb_seconds(iFreq):\n", | ||
" lRange = pd.date_range('1/1/1970', periods=2, freq=iFreq)\n", | ||
" delta_t = lRange[1] - lRange[0]\n", | ||
" return delta_t.total_seconds()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"FREQ_IN_SECONDS S 1.0 1.0\n", | ||
"FREQ_IN_SECONDS T 60.0 60.0\n", | ||
"FREQ_IN_SECONDS 30T 1800.0 30.0\n", | ||
"FREQ_IN_SECONDS H 3600.0 2.0\n", | ||
"FREQ_IN_SECONDS 12H 43200.0 12.0\n", | ||
"FREQ_IN_SECONDS D 86400.0 2.0\n", | ||
"FREQ_IN_SECONDS W 604800.0 7.0\n", | ||
"FREQ_IN_SECONDS M 2419200.0 4.0\n", | ||
"FREQ_IN_SECONDS 2M 5097600.0 2.107142857142857\n", | ||
"FREQ_IN_SECONDS Q 7862400.0 1.5423728813559323\n", | ||
"FREQ_IN_SECONDS 2Q 15811200.0 2.010989010989011\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"lSeconds = [1]\n", | ||
"for lFreq in [\"S\" , \"T\" , \"30T\" , \"H\", \"12H\", \"D\", \"W\" , \"M\" , \"2M\", \"Q\" , \"2Q\"]:\n", | ||
" lSeconds = lSeconds + [get_nb_seconds(lFreq)]\n", | ||
" print(\"FREQ_IN_SECONDS\", lFreq , lSeconds[-1] , lSeconds[-1] / lSeconds[-2])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"10.5" | ||
] | ||
}, | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"7*1.5" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 24, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"Timedelta('0 days 01:00:00')" | ||
] | ||
}, | ||
"execution_count": 24, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"delta_t" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"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.8.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |