Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I have a dataset of 60000×32. 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 126×32. How can I do that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading