我需要在单独的函数中转换熊猫帧值中的日期:
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?