시계열

Date and Time Data Types and Tools

Time Series Basics

Date Ranges, Frequencies, and Shifting

Generating Date Ranges

Frequencies and Date Offsets

Shifting (Leading and Lagging) Data

시간대 처리(Time Zone Handling)

파이썬 pytz 모듈에 정의되어 있는 시간대를 사용한다.

In [6]:
import pytz
import pandas as pd
import numpy as np

pytz의 속성인 common_timezones에 전세계 시간대가 정의되어 있다. 대한민국의 시간대는 다음과 같은 이름으로 사용되는 것을 알 수 있다.

In [3]:
[x for x in pytz.common_timezones if 'seoul' in x.lower()]
Out[3]:
['Asia/Seoul']

대한민국의 시간대 객체는 다음과 같이 만든다.

In [4]:
tz_ko = pytz.timezone('Asia/Seoul')
tz_ko
Out[4]:
<DstTzInfo 'Asia/Seoul' LMT+8:28:00 STD>

대부분의 판다스 메소드는 시간대로 이름 또는 시간대 객체를 인자로 받는다.

시간대 변경

판다스는 기본적으로 시간대를 자연스럽게 처리한다.

In [9]:
tr = pd.date_range('2018-01-5', periods=6)
tr
Out[9]:
DatetimeIndex(['2018-01-05', '2018-01-06', '2018-01-07', '2018-01-08',
               '2018-01-09', '2018-01-10'],
              dtype='datetime64[ns]', freq='D')
In [11]:
ts = pd.Series(np.arange(len(tr)), index=tr)
ts
Out[11]:
2018-01-05    0
2018-01-06    1
2018-01-07    2
2018-01-08    3
2018-01-09    4
2018-01-10    5
Freq: D, dtype: int32
In [13]:
print(ts.index.tz)
None

Periods and Period Arithmetic

Period Frequency Conversion

Quarterly Period Frequencies

Converting Timestamps to Periods (and Back)

Creating a PeriodIndex from Arrays

Resampling and Frequency Conversion

Downsampling

Upsampling and Interpolation

Resampling with Periods

Moving Window Functions

Conclusion