Pandas 数据框 to

编程入门 行业动态 更新时间:2024-10-11 23:17:58
本文介绍了Pandas 数据框 to_csv - 拆分为多个输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

将非常大的数据帧 (50GB) 拆分为多个输出(水平)的最佳/最简单的方法是什么?

What is the best /easiest way to split a very large data frame (50GB) into multiple outputs (horizontally)?

我想过做这样的事情:

stepsize = int(1e8) for id, i in enumerate(range(0,df.size,stepsize)): start = i end = i + stepsize-1 #neglect last row ... df.ix[start:end].to_csv('/data/bs_'+str(id)+'.csv.out')

但我敢打赌有更聪明的解决方案吗?

But I bet there is a smarter solution out there?

如 jakevdp 所述,HDF5 是存储大量数值数据的更好方法,但它不符合我的业务需求.

As noted by jakevdp, HDF5 is a better way to store huge amounts of numerical data, however it doesn't meet my business requirements.

推荐答案

在文件名中使用 id 否则将不起作用.您错过了 id,如果没有 id,则会出现错误.

Use id in the filename else it will not work. You missed id, and without id, it gives an error.

for id, df_i in enumerate(np.array_split(df, number_of_chunks)): df_i.to_csv('/data/bs_{id}.csv'.format(id=id))

更多推荐

Pandas 数据框 to

本文发布于:2023-11-11 05:13:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577473.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   Pandas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!