'How to get a range of Date in a column in Pandas?

Start Date End Date
2020-02-14 2020-02-18

so the output column looks like

Start Date End Date Date_range
2020-02-14 2020-02-18 [2020-02-14,2020-02-15,2020-02-16,2020-02-17,2020-02-18]


Solution 1:[1]

Use pd.date_range:

date_range = lambda x: pd.date_range(x['Start Date'], x['End Date']).date.tolist()
df['Date_range'] = df.apply(date_range, axis=1)
print(df)

# Output
   Start Date    End Date                                                    Date_range
0  2020-02-14  2020-02-18  [2020-02-14, 2020-02-15, 2020-02-16, 2020-02-17, 2020-02-18]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corralien