Python Forum
Getting the difference between two times in a Data Frame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting the difference between two times in a Data Frame
#1
I have a Pandas Dataframe where two columns contain times (stored as strings).

I want to get the minimum difference (hours, minutes, seconds) between both columns (Column1 and Column2).

I have converted both columns to times as per below and stored them in different dataframes:

Column1Times = pd.to_datetime(myDataFrame['Column1'], format='%H:%M:%S').dt.time
Column2Times = pd.to_datetime(myDataFrame['Column2'], format='%H:%M:%S').dt.time
To get the minimum time difference I use below, but I get
Error:
operand "-" not suuported.
print("Minimum difference is : ", (Column1Times - Column2Times).min())
Can someone please tell me what I am doing wrong?
Reply


Messages In This Thread
Getting the difference between two times in a Data Frame - by soulkid555 - Mar-20-2019, 04:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Grouping in pandas/multi-index data frame Aleqsie 3 695 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  Filtering Data Frame, with another value NewBiee 9 1,416 Aug-21-2023, 10:53 AM
Last Post: NewBiee
  Exporting data frame to excel dyerlee91 0 1,637 Oct-05-2021, 11:34 AM
Last Post: dyerlee91
  Pandas Data frame column condition check based on length of the value aditi06 1 2,704 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  Adding a new column to a Panda Data Frame rsherry8 2 2,133 Jun-06-2021, 06:49 PM
Last Post: jefsummers
  grouped data frame glitter 0 1,605 Feb-02-2021, 11:22 AM
Last Post: glitter
  how to filter data frame dynamically with the columns psahay 0 2,413 Aug-24-2020, 01:10 PM
Last Post: psahay
  Dropping Rows From A Data Frame Based On A Variable JoeDainton123 1 2,235 Aug-03-2020, 02:05 AM
Last Post: scidam
  How to shift data frame rows of specified column Mekala 0 1,911 Jul-21-2020, 02:42 PM
Last Post: Mekala
  HELP- DATA FRAME INTO TIME SERIES- BASIC bntayfur 0 1,770 Jul-11-2020, 09:04 PM
Last Post: bntayfur

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020