擅长:python、mysql、java
<p>我想出了一个更好的解决方案,对我原来的问题非常有效,那就是计算出完成一个工作单所花费的总时间。这个解决方案有助于克服excel时间格式这是一个对象类型。一旦转换为datetime[64]启用,一列减去另一列。你知道吗</p>
<p><code>import pandas as pd
from datetime import time
from datetime import timedelta
</code></p>
<p><code>df = pd.read_excel('C:/Users/Nativ_Zero/Desktop/work data/July.xls', index_col =0)</code></p>
<p><code>df_work = df[['WorkType', 'AST','AFT']]</code></p>
<p><code>#to convert time format column which is an object to datetime[64
df_work['AFT'] = pd.to_datetime(df_work['AFT'], format='%H:%M:%S', errors='coerce')
df_work['AST'] = pd.to_datetime(df_work['AST'], format='%H:%M:%S', errors='coerce')
</code></p>
<p><code>rm_work = df_work[df_work.WorkType == 'RM']
</code>
<code>hrs_ft = rm_work['AFT']
hrs_st = rm_work['AST']</code></p>
<p><code>hrs_t = hrs_ft - hrs_st</code></p>
<pre><code>Print(hrs_t)
</code></pre>