【问题标题】:Convert large CSV file into NetCDF将大型 CSV 文件转换为 NetCDF
【发布时间】:2015-05-19 12:56:17
【问题描述】:

我想将如下300万行150列的CSV格式的浮点矢量数据文件转换成NetCDF格式。

0.3,0.9,1.3,0.5,...,0.9
-5.1,0.1,1.0,8.4,...,6.7
...

首先,我尝试了类似 cache-all-the-data-and-then-convert-it 的算法,但它不起作用,因为它无法为缓存分配内存。 所以我需要用 convert-one-by-one 算法编写的代码。

有人知道这样的解决方案吗?

我的机器内存容量为8 MiB,C、Java、Python等任何编程语言都可以。

【问题讨论】:

  • 您想将所有数据存储为一个 300 万 x 150 的二维变量吗?

标签: csv vector machine-learning netcdf


【解决方案1】:

使用python可以逐行读取文件。

with open("myfile.csv") as infile:
    for line in infile:
        appendtoNetcdf(line)

因此您不必将所有文件内容加载到内存中。

查看netCDF4-python library,您可以轻松创建一个 netcdf4 或多个 netcdf4 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-20
    • 2018-05-10
    • 2021-06-21
    • 1970-01-01
    • 2018-07-14
    • 2023-01-21
    • 2021-10-21
    • 2017-11-05
    相关资源
    最近更新 更多