我有一個 netcdf 資料集,我想將時間轉換為 pandas 日期時間格式。條目如下所示:
<xarray.DataArray 'time' ()>
array(19810101.47916667)
Coordinates:
time float64 1.981e 07
Attributes:
axis: T
calendar: proleptic_gregorian
standard_name: time
units: day as %Y%m%d.%f
當我嘗試像這樣轉換資料時
pd.to_datetime(19810101.47916667,format='%Y%m%d.%f')
我收到錯誤“時間資料'19810101'與格式'%Y%m%d.%f'(匹配)不匹配”。我無法理解這里到底出了什么問題。特別是因為這正是 netcdf 資料中提到的格式(如上所示)。有人能告訴我我錯過了什么嗎?
uj5u.com熱心網友回復:
您只需將日期值設為如下字串:
pd.to_datetime("19810101.47916667",format='%Y%m%d.%f'
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/452701.html
