Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Converting to pandas datetime data does not match format

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You simply need to make your date value a string as below:

pd.to_datetime("19810101.47916667",format='%Y%m%d.%f'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading