'How to convert dtype of time axis from float32 to datetime64 for multiple files and then merge them in one file?

I have separate monthly netcdf files from 1940-2021 and I want to merge them in one single file. But the issue is that the time axis has dtype = float32 and I wonder how to merge them. So I need to convert float32 to datetime64. Please tell me a proper way to handle this problem. And if there is any alternate ways then let me know.

This is a example for how my time axis look for the year 1940 first month:-

time (time) float32 1.94e+05

long_name : time: yyyymm

reference_time : 194001.0

standard_name : time 

array([194001.], dtype=float32)

Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source