0

I have two columns in a dataframe in the format that it contains date and time as well. I need to find the difference in hours. When I try its giving type error.

Error: TypeError: unsupported operand type(s) for -: 'str' and 'str'.

Data example:

D1: 12/26/2014 7:45
    12/31/2014 6:30
D2: 1/1/2015 2:18
    1/1/2015 2:49

Need to find difference as D1-D2

Celius Stingher
  • 17,835
  • 6
  • 23
  • 53
Jeeva
  • 1
  • 2
  • 1
    Does this answer your question? [Calculate Pandas DataFrame Time Difference Between Two Columns in Hours and Minutes](https://stackoverflow.com/questions/22923775/calculate-pandas-dataframe-time-difference-between-two-columns-in-hours-and-minu) – Pygirl Jul 23 '20 at 11:41

1 Answers1

1

str function doesn't support it, you need to turn it into datetime format, look up about datetime module in python

official documentation: https://docs.python.org/3/library/datetime.html