简体   繁体   English

转换时间带走

[英]Converting time to take away

Hiya so I have a data frame which has the time something occurs in one column and the time that it ends in the next column.嗨,所以我有一个数据框,其中有某事发生在一列中的时间以及它在下一列中结束的时间。 I need to try and find the time difference between the two, but theyre both strings so it wont simply let me compare them, is there a way I can change them to ints (theyre in the format HH:MM:SS) I found a way to split them using.split (I've put what I did for the original time below, the I could do the same for the second column and work them out from there, but I was wondering if there was an easier way?我需要尝试找出两者之间的时间差,但它们都是字符串,所以它不会简单地让我比较它们,有没有办法可以将它们更改为整数(它们的格式为 HH:MM:SS)我找到了使用.split 拆分它们的方法(我已经把我最初做的事情放在下面,我可以对第二列做同样的事情并从那里解决它们,但我想知道是否有更简单的方法?
... TIA! ... TIA!

q = 0
for int in range(long):
    intel = df_data_bad_time1.loc[q,'Time']
    H_M_S = intel.split(':')
    df_data_bad_time1.loc[q,'Hours'] = H_M_S[0]
    df_data_bad_time1.loc[q,'Mins'] = H_M_S[1]
    df_data_bad_time1.loc[q,'Secs'] = H_M_S[2]
    q = q + 1
df_data_bad_time1['Hours'] = pd.to_numeric(df_data_bad_time1['Hours'], errors='coerce').astype('Int64')
df_data_bad_time1['Mins'] = pd.to_numeric(df_data_bad_time1['Mins'], errors='coerce').astype('Int64')
df_data_bad_time1['Secs'] = pd.to_numeric(df_data_bad_time1['Secs'], errors='coerce').astype('Int64')
df_data_bad_time1.head(15)

Here's a simple function I wrote, you can take a look at it and tell me if you don't understand anything: https://repl.it/@d4nieldev/subtract-time下面是我写的一个简单的function,有什么不懂的可以看一下告诉我: https://repl.it/@d4nieldev/subtract-time

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM