I have a dataframe which consists of 231840 rows. I need to split it into 161 separate tables, each table containing 1440 rows, i.e. the first table contains the first 1440 rows, the second table contains the next 1440 rows and so on until I get 161 separate tables with the combined number of rows being 231840 rows. Any ideas?
You can use, np.array_split to split the dataframe:
import numpy as np
dfs = np.array_split(df, 161) # split the dataframe into 161 separate tables
Edit (To assign a new col based on sequential number of df in dfs):
dfs = [df.assign(new_col=i) for i, df in enumerate(dfs, 1)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With