我正试图按照Pandas: add timedelta column to datetime column (vectorized)中的步骤,通过转换“pandas._libs.tslibs.timestaps.Timestamp”系列,向我的数据帧添加一个时间增量列
代码:
df = pd.DataFrame([['2020-07-25 09:26:28',2],['2020-07-25 09:26:2',10],['2020-07-25 09:26:30',203],['2020-07-25 09:26:31',30]],
columns = ['Time','Load'])
df['Time'] = pd.to_datetime(df['Time'])
print(df)
print(type(df["Time"][0]))
df_static['time_delta'] = pd.to_timedelta(df_static['Time'])
However, I get the following error:
TypeError:无法将数据类型datetime64[ns]转换为timedelta64[ns]
What am I doing wrong?
如果需要从datetimes转换为TimeDelta的时间,请将datetimes转换为} 格式:
HH:MM:SS
by ^{相关问题 更多 >
编程相关推荐