<p>说实话有点混乱。你能不能更具体一点,你的主要目标是什么,并提供更多的资料,日期是如何显示在你的excel文件。你知道吗</p>
<hr/>
<p>第二次编辑*
|我试着用代码注释我写的东西。你知道吗</p>
<hr/>
<p>我举了一个类似的例子,只是想知道我能帮你什么。你知道吗</p>
<p>我的excel文件如下所示:</p>
<p><a href="https://i.stack.imgur.com/Q4AIG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q4AIG.png" alt="enter image description here"/></a></p>
<p>这就是以非常简单的方式读取和计算差异的代码:</p>
<pre><code>import pandas as pd
df = pd.read_excel('dates.xlsx') #reading my excel
timeStart = [] #declaring 2 lists where I'm gonna put my records
timeEnd = []
#Here I append my values from the excel to my lists
for value in df.get('col1'):
timeStart.append(value)
for value in df.get('col2'):
timeEnd.append(value)
#I suppose they both have the same amount of elements in list
#therefore I can iterate for the len of any list between timeStart and timeEnd
for i in range(len(timeStart)):
#datetime.time object doesn't allow '-' operator to catch it's time difference,
#you can calculate it like this having how much hours, minutes or seconds
#spent working. Or you can just concatenate all 3 results to get it all.
hours = timeEnd[i].hour - timeStart[i].hour #hours difference
minutes = timeEnd[i].minute - timeStart[i].minute #minutes difference
seconds = timeEnd[i].second - timeStart[i].second #second difference
print(type(hours), type(minutes), type(seconds)) #all my results are int
print(hours, minutes, seconds) #I can see the difference from one time to another
</code></pre>
<p>这是我在输出中得到的:</p>
<pre><code><class 'int'> <class 'int'> <class 'int'> #Here you can see I have 3 int types
1 30 15 #read as 1 hour 30 minutes and 15 seconds
<class 'int'> <class 'int'> <class 'int'>
1 30 15
<class 'int'> <class 'int'> <class 'int'>
1 30 15
<class 'int'> <class 'int'> <class 'int'>
1 30 15
<class 'int'> <class 'int'> <class 'int'>
1 30 15
<class 'int'> <class 'int'> <class 'int'>
1 30 15
<class 'int'> <class 'int'> <class 'int'>
1 30 15
<class 'int'> <class 'int'> <class 'int'>
1 30 15
<class 'int'> <class 'int'> <class 'int'>
1 30 15
[Finished in 0.5s]
</code></pre>