【发布时间】:2021-02-10 00:32:19
【问题描述】:
我正在使用 NetCDF 文件 (.nc) - 600+MB。
import netCDF4
from netCDF4 import num2date
import numpy as np
import os
import pandas as pd
# Open netCDF4 file
file_location = '2m dewpoint temperature.nc'
f = netCDF4.Dataset(file_location)
为了将文件转换为 CSV,我首先找到了它的属性
# Find the attributes
print(f.variables.keys())
Output: dict_keys(['longitude', 'latitude', 'expver', 'time', 'd2m'])
然后,提取变量并尝试获取尺寸时
# Extract variable
d2m = f.variables['d2m']
# Get dimensions
time_dim, lat_dim, lon_dim = d2m.get_dims()
time_var = f.variables[time_dim.name]
times = num2date(time_var[:], time_var.units)
latitudes = f.variables[lat_dim.name][:]
longitudes = f.variables[lon_dim.name][:]
我收到以下错误
time_dim, lat_dim, lon_dim = d2m.get_dims()
ValueError:要解压的值太多(预计 3 个)
这里发生了什么,我应该如何解决?
编辑 1
print(d2m.get_dims()) 的输出是
(<class 'netCDF4._netCDF4.Dimension'>: name = 'time', size = 94750, <class 'netCDF4._netCDF4.Dimension'>: name = 'expver', size = 2, <class 'netCDF4._netCDF4.Dimension'>: name = 'latitude', size = 33, <class 'netCDF4._netCDF4.Dimension'>: name = 'longitude', size = 53)
编辑 2
df.head() 为@RobertWilson's suggestion
【问题讨论】:
标签: python pandas export-to-csv netcdf netcdf4