Py学习  »  Python

如何将numpy datetime64[ns]转换为python datetime?

Boris Salimov • 5 年前 • 2317 次点击  

我需要在单独的函数中转换熊猫帧值中的日期:

 def myfunc(lat, lon, when):
        ts = (when - np.datetime64('1970-01-01T00:00:00Z','s')) / np.timedelta64(1, 's')
        date = datetime.datetime.utcfromtimestamp(ts)
        print("Numpy date= ", when, " Python date= ", date)
        return float(90) - next_func(lat, lon, date)

调用此函数:

new_df['new_column'] =  np.vectorize(my_func)(lat, lon, new_df['datetime(LT)'])  

但它会引起错误:

ufunc subtract cannot use operands with types dtype('int64') and dtype('<M8[s]')

如何将numpy datetime64[ns]转换为python datetime?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38395
 
2317 次点击  
文章 [ 2 ]  |  最新文章 5 年前