Jeeva
Jeeva

Reputation: 1

Difference between two date columns in a dataframe using python

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

Upvotes: 0

Views: 46

Answers (1)

Nauman Akram
Nauman Akram

Reputation: 11

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

Upvotes: 1

Related Questions