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

原文地址:https://www.cnblogs.com/zzay/p/14743503.html