简体   繁体   中英

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?
... 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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