xarray 数据集中的循环时间记录
Round time records in xarray dataset
我有时间维度为“'2017-08-13T00:00:00.000000000', '2017-08-18T00:00:00.000000000'
”的 xarray 数据集。我想去掉小时、分钟和秒,保留'2017-08-13'
、'2017-08-18'
。到目前为止我尝试的是以下内容。
ds['time'].dt.round('D')
ds['time'].dt.floor('D')
但他们return原始日期格式。
如果有任何帮助,我将不胜感激。
四舍五入或取整时间可以更改它们的小时、分钟、秒等值,但它们的默认字符串表示仍将保留它们,即使它们为零。如果你只想打印出日期的年、月、日,你可以使用 strftime
method on the DatetimeAccessor
:
ds.time.dt.strftime("%Y-%m-%d")
我有时间维度为“'2017-08-13T00:00:00.000000000', '2017-08-18T00:00:00.000000000'
”的 xarray 数据集。我想去掉小时、分钟和秒,保留'2017-08-13'
、'2017-08-18'
。到目前为止我尝试的是以下内容。
ds['time'].dt.round('D')
ds['time'].dt.floor('D')
但他们return原始日期格式。 如果有任何帮助,我将不胜感激。
四舍五入或取整时间可以更改它们的小时、分钟、秒等值,但它们的默认字符串表示仍将保留它们,即使它们为零。如果你只想打印出日期的年、月、日,你可以使用 strftime
method on the DatetimeAccessor
:
ds.time.dt.strftime("%Y-%m-%d")