我可以使用以下方法将数据帧拆分为多个块:
def split_df_into_num_chunks(cls, df, chunks = 10):
list_of_df = list()
initial_len = len(df.index)
chunk_size = initial_len // chunks
for i in range(chunks):
list_of_df.append(df[i*chunk_size:(i+1)*chunk_size])
if (i+1)*chunk_size < initial_len:
list_of_df.append(df[(i+1)*chunk_size:initial_len])
return list_of_df
但是我无法计算出如何拆分DataFrameGroupBy例如
id date qty
0 540689582 2017-09-22 00:00:00+00:00 41
1 540689582 2017-09-23 00:00:00+00:00 44
2 540689582 2017-09-24 00:00:00+00:00 52
3 540689583 2017-09-22 00:00:00+00:00 56
4 540689583 2017-09-23 00:00:00+00:00 31
我想将DataFrameGroupBy拆分为n个大小相等的子DataFrameGroupBys,并且我想保留ID的组(即保持每个组完整,在拆分时在组之间拆分)
有任何线索吗?