Home > other >  How can I split a data into small datasets by rows?
How can I split a data into small datasets by rows?

Time:03-04

I have a dataset of 60000x32. I want to split it like that first split= (0:126,:) second=(126:252,:) ` third= (252:378,:) .. .. till the end...

It should be in that order. Every split needs to be in the size of 126x32. How can I do that?

CodePudding user response:

try something like this

def segment_data(data, n_rows):
    """
    :param data: dataframe with 60000 rows and 32 features
    :param n_rows: number of rows in each segment
    :return: list of dataframes with 126 rows and 32 features
    """
    segments = []
    for i in range(0, len(data), n_rows):
        segment = data.iloc[i:i   n_rows, :]
        segments.append(segment)
    return segments


segments = segment_data(data, 126)
  • Related