def nc_to_dataframe(nc_fname,
columns=slice(None)):
"""
Return a pandas data frame containing the information in the
netCDF file *nc_fname*. Return it and a mapping to the header
metadata. Use *columns* to select columns (via a list of column
names).
"""
root = Dataset(nc_fname)
data = {}
data.update({dim: root[dim][:] for dim in root.dimensions if dim != 'time'})
index = data['time'] = map(fromJ2000, root['time'][:])
return (PD.DataFrame(data=data, index=index)[columns],
{x: getattr(root, x) for x in root.ncattrs()})
评论列表
文章目录