【发布时间】:2021-02-07 10:01:16
【问题描述】:
我有一个 netCDF 文件,其中时间以天为单位,我猜是 0000 年 1 月 1 日。但是,它们是整数,见下文,一旦加载 xarray 就无法解码时间单位。
<xarray.DataArray 'days' (time: 87600)>
array([679352., 679353., 679354., ..., 766949., 766950., 766951.])
Dimensions without coordinates: time
Attributes:
units: days_since_Jan11900
long_name: calendar_days
我想用 pandas 把它们变成日期时间。到目前为止我已经这样做了
import pandas as pd
import xarray as xr
ds = xr.open_dataset(path + '09_future_predictions/Fire weather/temp/tmax_HadGEM2-CC.nc', decode_times = False)
tmax = ds.tmax.data
time = ds.days
time = pd.to_datetime(time.data)
但是,我最终让 pandas 以毫秒为单位读取整数,见下文:
DatetimeIndex(['1970-01-01 00:00:00.000679352',
'1970-01-01 00:00:00.000679353',
'1970-01-01 00:00:00.000679354',
'1970-01-01 00:00:00.000679360',
'1970-01-01 00:00:00.000679361',
...
'1970-01-01 00:00:00.000766942',
dtype='datetime64[ns]', length=87600, freq=None)
我可以做些什么来改变它,使第一个变量是1860-01-01?
【问题讨论】:
-
为什么不能将它作为普通的 float/int 读取到 pandas,然后使用诸如 netcdf.num2date/matplotlib.date.num2date 之类的应用函数?
-
怎么样?能详细点吗?
标签: python pandas netcdf python-xarray