【发布时间】:2020-12-07 02:11:13
【问题描述】:
我正在努力将几个 Berekeley Earth netCDF 文件转换为 CSV 或其他表格格式。我意识到以前也有人提出过类似的问题,但我无法应用我遇到的任何解决方案。
例如,this dataset。
-
netCDF 实用程序中的
ncdump似乎不会生成实际的 CSV 文件。我找不到任何有关如何执行此操作的说明。 - 我尝试使用
xarray.to_dataframe()将数据加载到pandas数据帧中,但我的笔记本无法分配所需的内存。
In [1]: import xarray as xr
In [2]: import pandas as pd
In [3]: nc = xr.open_dataset('Complete_TAVG_Daily_EqualArea.nc')
In [4]: nc
Out[4]:
<xarray.Dataset>
Dimensions: (map_points: 5498, time: 50769)
Dimensions without coordinates: map_points, time
Data variables:
longitude (map_points) float32 ...
latitude (map_points) float32 ...
date_number (time) float64 ...
year (time) float64 ...
month (time) float64 ...
day (time) float64 ...
day_of_year (time) float64 ...
land_mask (map_points) float64 ...
In [5]: df = nc.to_dataframe()
---------------------------------------------------------------------------
MemoryError Traceback (most recent call last)
(...)
MemoryError: Unable to allocate 532. MiB for an array with shape (279127962,) and data type int16
- 我尝试使用
Panoply进行转换。 CSV 导出似乎只能将单个变量(我希望将其视为一列)导出到单行文件中。
我一定错过了什么。有人可以帮我吗?
【问题讨论】:
-
您使用的是 Jupyter Notebook?您是否尝试过将其作为标准脚本运行?
-
这没什么区别。顺便说一句,在 Windows 和 Linux 上的结果相同......