Say I have a data frame with two columns
Start End
1/1/2015 1/5/2015
1/10/2015 1/12/2015
What would be the best method to get the dates in between the start and end (the actual dates, not the number of days in between) including the start and end dates.
For example I would get 1/1/2015, 1/2/2015, ..., 1/5/2015.
The reason I want to do this is to find out how many weekend are between two dates.
Here is the example data frame plus the code to parse dates quickly.
def lookup(s):
"""
This is an extremely fast approach to datetime parsing.
For large data, the same dates are often repeated. Rather than
re-parse these, we store all unique dates, parse them, and
use a lookup to convert all dates.
"""
dates = {date:pd.to_datetime(date) for date in s.unique()}
return s.map(dates)
df = pd.DataFrame({"Start": ["1/1/2015", "1/10/2015"], "End": ["1/5/2015", "1/12/2015"]})
df["Start"] = lookup(df["Start"])
df["End"] = lookup(df["End"])
If someone knows a better way to do this please let me know as I think there is a better way to find the number of weekends between two dates.
I have tried to understand the pd.date_range() function and have tried applying it like this.
df["between"] = pd.date_range(df["Start"], df["End"])
But get an error saying it cannot convert the input, I know I am using this function incorrectly. I think I need to use apply but am unsure how to use it with this function.
Any help is appreciated. Please let me know if you need any more information.
Thank you for your time.