Given dates:
my_guess = '2014-11-30'
their_guess = '2017-08-30'
How do I split the delta between the dates, returning the correct calendar date?
As we known, the dates are recorded as serial number in Excel, and to get a midpoint of two numbers, you need to add two numbers together and then divided by 2.
To convert a datetime to seconds, subtracts the input datetime from the epoch time. For Python, the epoch time starts at 00:00:00 UTC on 1 January 1970. Subtraction gives you the timedelta object. Use the total_seconds() method of a timedelta object to get the number of seconds since the epoch.
You can use pandas. Series. between() method to select DataFrame rows between two dates. This method returns a boolean vector representing whether series element lies in the specified range or not.
One way would be to use datetime
. Find the difference between two dates, halve it, and add it on the earlier date:
>>> from datetime import datetime
>>> a = datetime(2014, 11, 30)
>>> b = datetime(2017, 8 ,30)
>>> a + (b - a)/2
2016-04-15 00:00:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With