def create_sliding_frames(dataframe, frame_length=12):
"""
Wrapper for the extend_data_with_sliding_frames function which works with numpy arrays.
This version does the data-frame conversion for us.
:param dataframe: The dataframe to extend.
:param frame_length: The frame length to use in the resulting extended data frame.
:return: A new data frame where the original dataframe has been extended with sliding frames.
"""
extended_array = extend_data_with_sliding_frames(dataframe.values)
# We should preserve the columns of the dataframe, otherwise
# concatenating different dataframes along the row-axis will give
# wrong results
window_columns = dataframe.columns
column_index = pd.MultiIndex.from_product([range(frame_length),
window_columns],
names=['window', 'feature'])
return pd.DataFrame(data=extended_array,
columns=column_index)
评论列表
文章目录