# data = data[['market', 'time', 'open', 'high', 'low', 'close', 'volume']] # transform this dataset so to 'market', 'start', 'column', 'value1', 'value2', 'value3', 'value(n)' import pandas as pd import numpy as np from tqdm import tqdm columns = ['open','close','volume', 'rsi', 'sma'] window_size = 10 def create_sequences(df, columns=columns, window_size=window_size): # group by market grouped = df.groupby('market') # create a list of dataframes dfs = [] for name, group in tqdm(grouped): # create a new dataframe new_df = pd.DataFrame() new_df['market'] = name # create a list of lists sequences = [] # only include the close column # iterate over the rows of the dataframe for i in range(len(group) - window_size): # create a sequence sequence = group.iloc[i:i+window_size][columns].values # transpose the sequence so that it is a column sequence = sequence.T # create a dataframe from the sequence sequence = pd.DataFrame(sequence) # add the market, time, column_name to the sequence sequence['market'] = name sequence['time'] = group.iloc[i+window_size]['time'] sequence['column'] = columns # set market, time as the first columns and index sequence = sequence.set_index(['market', 'time', 'column']) # add the sequence to the list of sequences sequences.append(sequence) if len(sequences) == 0: continue # create a dataframe from the list of lists new_df = pd.concat(sequences) # add the dataframe to the list of dataframes dfs.append(new_df) # concatenate the list of dataframes final_df = pd.concat(dfs) return final_df df = pd.read_csv('indicators.csv') # create the sequences sequences = create_sequences(df, columns=columns, window_size=15) # save the sequences to a new file sequences.to_csv('sequences.csv')