import pandas as pd
import datetime
# 加载数据
def parser(x):
return datetime.datetime.strptime(x, '%Y/%m/%d')
ser = pd.read_csv('../LSTM系列/LSTM单变量1/data_set/shampoo-sales.csv',
header=0, parse_dates=[0], index_col=0, date_parser=parser).squeeze('columns')
def timeseries_to_supervised(data, lag=1):
df = pd.DataFrame(data)
columns = [df.shift(i) for i in range(1, lag+1)]
columns.append(df)
df = pd.concat(columns, axis=1)
df.fillna(0, inplace=True)
return df
X = ser.values
supervised = timeseries_to_supervised(X, 1)
print(supervised.head())
标签:df,parser,datetime,学习,监督,supervised,pd,序列,columns
From: https://www.cnblogs.com/lotuslaw/p/17103769.html