我很难解决非常简单的情况:) - 需要在Pandas中为Date添加毫秒。
df['DATE'] = pd.to_datetime(df['DATE'])
df['date_start_time'] = pd.to_timedelta(df['DATE']) + pd.to_timedelta(df['QTR_HR_START']/1000)
确定我收到了错误:
文件“C:\ Anaconda \ lib \ site-packages \ pandas \ tseries \ timedeltas.py”, 第97行,在_coerce_scalar_to_timedelta_type中 return tslib.convert_to_timedelta(r,unit)文件“tslib.pyx”,第1283行,在pandas.tslib.convert_to_timedelta(pandas \ tslib.c:22255)
在pandas.tslib.convert_to_timedelta64中输入“tslib.pyx”,第1338行 (pandas \ tslib.c:22901)ValueError:timedelta标量的类型无效:
这样做的正确方法是什么?
Unnamed: 0 DATE QTR_HR_START QTR_HR_END PERIOD_LENGTH
0 1 2013-01-01 21600000 22499000 899000
1 2 2013-01-01 22500000 23399000 899000
2 3 2013-01-01 23400000 24299000 899000
3 4 2013-01-01 23400000 24299000 899000
4 5 2013-01-01 24300000 25199000 899000
5 6 2013-01-01 25200000 26099000 899000
6 7 2013-01-01 25200000 26099000 899000