Python으로 배우는 시계열 데이터 Machine Learning
Chris Holdgraf
Fellow, Berkeley Institute for Data Science
from glob import glob
files = glob('data/heartbeat-sounds/files/*.wav')
print(files)
['data/heartbeat-sounds/proc/files/murmur__201101051104.wav',
...
'data/heartbeat-sounds/proc/files/murmur__201101051114.wav']
import librosa as lr
# `load` accepts a path to an audio file
audio, sfreq = lr.load('data/heartbeat-sounds/proc/files/murmur__201101051104.wav')
print(sfreq)
2205
이 경우 샘플링 주파수는 2205로, 초당 2205개의 샘플이 존재합니다
각 샘플에 대한 인덱스 배열을 생성하고 샘플링 주파수로 나눕니다
indices = np.arange(0, len(audio))
time = indices / sfreq
N-1번째 데이터 포인트의 타임스탬프를 구한 후, linspace()로 0부터 해당 시간까지 보간합니다
final_time = (len(audio) - 1) / sfreq
time = np.linspace(0, final_time, sfreq)
data = pd.read_csv('path/to/data.csv')
data.columns
Index(['date', 'symbol', 'close', 'volume'], dtype='object')
data.head()
date symbol close volume
0 2010-01-04 AAPL 214.009998 123432400.0
1 2010-01-04 ABT 54.459951 10829000.0
2 2010-01-04 AIG 29.889999 7750900.0
3 2010-01-04 AMAT 14.300000 18615100.0
4 2010-01-04 ARNC 16.650013 11512100.0
dtypes 속성으로 각 열의 객체 유형을 확인할 수 있습니다df['date'].dtypes
0 object
1 object
2 object
dtype: object
to_datetime() 함수를 사용합니다df['date'] = pd.to_datetime(df['date'])
df['date']
0 2017-01-01
1 2017-01-02
2 2017-01-03
Name: date, dtype: datetime64[ns]
Python으로 배우는 시계열 데이터 Machine Learning