在python中将NetCDF转换为csv时出错

时间:2018-10-06 14:47:11

标签: python python-3.x pandas csv netcdf

我正在尝试将NetCDF转换为.csv,就像this post一样。我正在使用具有类似变量的netCDF文件:'time','lat','lon','total'

我已复制了最佳答案的代码:

import netCDF4
import pandas as pd

file = 'file_path'
nc = netCDF4.Dataset(file, mode='r')

nc.variables.keys()

lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
time_var = nc.variables['time']
dtime = netCDF4.num2date(time_var[:],time_var.units)
total = nc.variables['total'][:]

total_ts = pd.Series(total, index=dtime) 
total_ts.to_csv('total.csv',index=True, header=True)

但是我遇到2个错误:

UserWarning: WARNING: valid_range not used since it cannot be safely cast to variable data type
dtime = netCDF4.num2date(time_var[:],time_var.units)

total_ts = pd.Series(total,index=dtime)
Exception: Data must be 1-dimensional

由于代码完全相同并且netCDF文件非常相似,所以我不确定出了什么问题。

0 个答案:

没有答案