pandas水平拆分dataframe

def numpy_split_pd(df, split_num):
    # 使用numpy拆分DataFrame 把索引均分 均分后再用索引拆分DataFrame
    lst_index = list(map(lambda a: a.tolist(), numpy.array_split(df.index.tolist(), split_num)))
    for idx in lst_index:
        df_split = df.iloc[idx[0]: idx[-1] + 1]
        yield df_split

传入dataframe,和需要拆分的个数 可以平均拆分dataframe

posted @ 2021-05-08 08:54  Young_Mo  阅读(488)  评论(0编辑  收藏  举报