padnas超大csv写入不同sheet

我若为王 2020-09-10 AM 2086℃ 0条
#超大csv按条数分sheet写到excel,name为csv文件名,nums为分割条数
def big_csv_to_xlsx(name,nums):
    #拆分csv
    max_rows = nums
    dataframes = []
    df=pd.read_csv(name+'.csv')
    while len(df) > max_rows:
        top = df[:max_rows]
        dataframes.append(top)
        df = df[max_rows:]
    else:
        dataframes.append(df)
    #保存到不同sheet
    write = pd.ExcelWriter(name+'.xlsx')
    for _, frame in enumerate(dataframes):
        frame.to_excel(write, index=False,sheet_name=str(_))
    write.save()
    write.close()
标签: pandas

非特殊说明,本博所有文章均为博主原创。

评论啦~


鲁ICP备14003065号-4