我有一个excel数据库,如下所示:
我想使用python获得新列(ResponseTime)=(endtimestarttime)。我正在使用以下python代码:
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
new = pd.read_excel("single_file.xlsx")
sf=pd.DataFrame(new)
sf['Res_Time'] = sf['EndTime'] - sf['StartTime'])
它向我显示了以下错误:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
如何在两列中减去时间值
您试图减去两个字符串,为了首先处理日期,必须使用^{} 将列转换为datetime
使用
format
,您可以更改字符串解析,检查strftime相关问题 更多 >
编程相关推荐