I have a netcdf dataset and I want to convert the time to pandas datetime format. The entries look like this:
<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
When I try to convert the data like this
pd.to_datetime(19810101.47916667,format='%Y%m%d.%f')
I get the error "time data '19810101' does not match format '%Y%m%d.%f' (match)". I fail to undertand what exactly is going wrong here. Especially since this is exactly the format mentioned in the netcdf data (as you can see above). Can someone tell me what I am missing?
CodePudding user response:
You simply need to make your date value a string as below:
pd.to_datetime("19810101.47916667",format='%Y%m%d.%f'