Pandas Number Of Days Between Dates
How would I find the number of days between the current date and df['date'] and create a new column with the results.
date count user days_since
2013/02/22 145 apple ###
2005/01/16 234 banana ###
2011/02/01 521 orange ###
2001/01/14 10 grape ###
Thanks!
Posted May 11, 2013, 5:37 PM UTC
13
If you want to use the standard library, you can use the
datetimemodule, but it's a bit awful. There's alsoarrow, a third party library for working with dates.I've used
datetime, essentially, you'd create adatetime.datetimefrom the date column, and then one of the current date, subtract one from the other to get adatetime.timedelta. From that you can extract seconds with thetotal_secondsmethod and use that to determine days. That's off the top of my head, I assume that the process could be done more efficiently.You can just ask the
datetime.timedeltafor its.daysdirectly.[deleted]