Last active
February 15, 2022 14:31
-
-
Save ozturkib/331cec25082ba948c5d3cd22c67eafd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Take the difference of only the time portion of timestamps ignoring the date portion through dataframe columns. | |
import pandas as pd | |
import numpy as np | |
import datetime as dt | |
import datetime | |
from datetime import timedelta, datetime, date | |
df3 = pd.read_csv("combine.csv", parse_dates=['bl.start','bl.end','ex.start','ex.end','ExamStart','ScrathcpadStart']) | |
# extracting time from timestamp | |
df3['bl.start1'] = df3['bl.start'].dt.time | |
df3['ExamStart2'] = df3['ExamStart'].dt.time | |
#It has looping to subtract two time portions. | |
#Take into account that looping through dataframes with pandas is NOT efficient way! | |
#Dont have too much time to dive into your problem but have a look at timestamp, timedelta, timedate. | |
#So you need to make it better! | |
df3['diff_seconds'] = [datetime.combine(date.min, df3['bl.start1'][ind]) - datetime.combine(date.min, df3['ExamStart2'][ind]) for ind, row in df3.iterrows()] | |
df3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment