Python 3.x 获取文件的持续时间
我的数据文件由大约100万行时间序列数据组成。它已使用Python 3.x 获取文件的持续时间,python-3.x,pandas,time-series,python-datetime,Python 3.x,Pandas,Time Series,Python Datetime,我的数据文件由大约100万行时间序列数据组成。它已使用df=pd.read\u csv(…)读入Python。 我正在寻找一种方法来获取文件的持续时间(以秒为单位),我正在寻找的输出只是一个给出持续时间的数字 下面显示了显示数据结构的第一个和最后5个条目: 测向头(5) df.tail(5) IIUC,让我们试试,给定的时间戳是DatetimeIndex: 首先,让我们索引到datetime: df.index = pd.to_datetime(df.index) df.reset_inde
df=pd.read\u csv(…)
读入Python。
我正在寻找一种方法来获取文件的持续时间(以秒为单位),我正在寻找的输出只是一个给出持续时间的数字
下面显示了显示数据结构的第一个和最后5个条目:
测向头(5)
df.tail(5)
IIUC,让我们试试,给定的时间戳是DatetimeIndex: 首先,让我们索引到datetime:
df.index = pd.to_datetime(df.index)
df.reset_index()['TimeStamp'].diff().sum().total_seconds()
或
我尝试了此操作,但出现了一个错误:
TypeError:-:'str'和'str'的操作数类型不受支持。
X Y Z
TimeStamp
2017-05-12 13:18:59.950 -0.045288 -0.018508 1.010065
2017-05-12 13:18:59.960 -0.045412 -0.018438 1.009695
2017-05-12 13:18:59.970 -0.045671 -0.018282 1.009768
2017-05-12 13:18:59.980 -0.045889 -0.018029 1.010952
2017-05-12 13:18:59.990 -0.045657 -0.017709 1.013374
df.index = pd.to_datetime(df.index)
df.reset_index()['TimeStamp'].diff().sum().total_seconds()
(df.index[-1] - df.index[0]).total_seconds()