pandas date_range

index = pd.date_range(start='2020-8-15', end = '2021-8-11', freq='M')
print(index)

>>>DatetimeIndex(['2020-08-31', '2020-09-30', '2020-10-31', '2020-11-30',
                 '2020-12-31', '2021-01-31', '2021-02-28', '2021-03-31',
                 '2021-04-30', '2021-05-31', '2021-06-30', '2021-07-31'],
                 dtype='datetime64[ns]', freq='M')

Here is what the above code is Doing:
1. We’re creating a DatetimeIndex object with a start date of 2020-8-15 and an end date of 2021-8-11.
2. We’re setting the frequency to ‘M’, which stands for monthly.
3. We’re printing the index to the console.

As you can see, the index contains a date for every month between August 2020 and July 2021.

Now let’s create a DataFrame with this index:

import pandas as pd

index = pd.date_range(start=’2020-8-15′, end = ‘2021-8-11′, freq=’M’)

data = {‘Apples’: [30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],
‘Bananas’: [21, 34, 45, 56, 67, 78, 89, 90, 101, 112, 123, 134]}

df = pd.DataFrame(data, index=index)
print(df)

>>> Apples Bananas
2020-08-31 30 21
2020-09-30 40 34
2020-10-31 50 45
2020-11-30 60 56
2020-12-31 70 67
2021-01-31 80 78
2021-02-28 90 89
2021-03-31 100 90
2021-04-30 110 101
2021-05-31 120 112
2021-06-30 130 123
2021-07-31 140 134

As you can see, the DataFrame contains two columns with monthly sales data for apples and bananas.

The index contains a date for every month between August 2020 and July 2021.

Now let’s create a line chart that visualizes this data:

import pandas as pd
import matplotlib.pyplot as plt

index = pd.date_range(start=’2020-8-15′, end = ‘2021-8-11′, freq=’M’)

data = {‘Apples’: [30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],