Splitting / Divide dataframe every 10 rows

  dataframe, pandas, pandas-groupby, python, tuples

i’m trying to split my dataframe into 10 rows and find the aggregate function (mean, SD, etc) for each 10 rows then merge it into 1 dataframe again. Previously i had grouped the data using .groupby functio, but having trouble to split the data into 10 rows.

this is what i have code :

  def sorting (train):
    grouped = train.groupby(['Activity']).
    l_grouped=list(grouped)

i have turn the grouped result into list, but i don’t know if i could separate the rows from each tuple?
i could access the grouped result using :

  for i in range(len(df_sort)):
      print(df_sort[i][1])

but the result is in tuple and i don’t know if i could separate each 10 rows from the tuple. Thank you

Source: Python Questions

LEAVE A COMMENT