0

I have a scenario where i have to split the data frame which has n rows into multiple dataframe for every 35 rows. like lets say I have 100 rows in the dataframe. The first dataframe should have 1-35 rows the second dataframe should have 36-70 then third df should have the remaining datas.

ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
sai8s
  • 11
  • 1
  • 4
  • `dfs = split_dataframe(df, chunk_size=35)` from https://stackoverflow.com/a/28882020/13138364 – tdy Apr 19 '21 at 08:35

1 Answers1

2

You can just use a simple loop, and can access the dataframe slice via indexing:

for i in range(0, df.shape[0], 35):
    print(df[i:i+35])

If you want, you can just store them in a list:

dfList = []
for i in range(0, df.shape[0], 35):
    dfList.append(df[i:i+35])
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45