In [1]:
from ahh import pre
import pandas as pd

In [16]:
# make data up
dts = pd.date_range('2016-01-01', periods=18, freq='27D')
years = dts.year
months = dts.month
days = dts.day
data = list(range(len(dts)))
df = pd.DataFrame(data=dict(data=data, years=years, months=months, days=days))
df.to_csv('./example_data/timeseries.csv', index=False)
df


Out[16]:
data days months years
0 0 1 1 2016
1 1 28 1 2016
2 2 24 2 2016
3 3 22 3 2016
4 4 18 4 2016
5 5 15 5 2016
6 6 11 6 2016
7 7 8 7 2016
8 8 4 8 2016
9 9 31 8 2016
10 10 27 9 2016
11 11 24 10 2016
12 12 20 11 2016
13 13 17 12 2016
14 14 13 1 2017
15 15 9 2 2017
16 16 8 3 2017
17 17 4 4 2017

In [17]:
# combine years, months, days into datetime index and clears the old date columns
df = pre.read_csv('./example_data/timeseries.csv', year='years', month='months', day='days', clear=True)
df


Out[17]:
data
2016-01-01 0
2016-01-28 1
2016-02-24 2
2016-03-22 3
2016-04-18 4
2016-05-15 5
2016-06-11 6
2016-07-08 7
2016-08-04 8
2016-08-31 9
2016-09-27 10
2016-10-24 11
2016-11-20 12
2016-12-17 13
2017-01-13 14
2017-02-09 15
2017-03-08 16
2017-04-04 17

In [20]:
# can also automatically set date string column to datetime
dts = pd.date_range('2016-01-01', periods=18, freq='27D')
data = list(range(len(dts)))
df = pd.DataFrame(data=dict(data=data, datetime=dts))
df.to_csv('./example_data/timeseries_dates.csv', index=False)
df


Out[20]:
data datetime
0 0 2016-01-01
1 1 2016-01-28
2 2 2016-02-24
3 3 2016-03-22
4 4 2016-04-18
5 5 2016-05-15
6 6 2016-06-11
7 7 2016-07-08
8 8 2016-08-04
9 9 2016-08-31
10 10 2016-09-27
11 11 2016-10-24
12 12 2016-11-20
13 13 2016-12-17
14 14 2017-01-13
15 15 2017-02-09
16 16 2017-03-08
17 17 2017-04-04

In [21]:
df = pre.read_csv('./example_data/timeseries_dates.csv', time='datetime')
df


Out[21]:
data
datetime
2016-01-01 0
2016-01-28 1
2016-02-24 2
2016-03-22 3
2016-04-18 4
2016-05-15 5
2016-06-11 6
2016-07-08 7
2016-08-04 8
2016-08-31 9
2016-09-27 10
2016-10-24 11
2016-11-20 12
2016-12-17 13
2017-01-13 14
2017-02-09 15
2017-03-08 16
2017-04-04 17

In [ ]:


In [ ]: