Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating data frame with Mondays of all the month as index

I want to create a data frame with Mondays of every month as index.
Ex:

Date blah blah
4/7/2022. . .
11/7/2022 . .
18/7/2022
25/7/2022.

How can I get that using python

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use pandas.date_range, here setting the number of values to 20 (you could also chose an end date):

pd.date_range('2022-07-04', periods=20, freq='7D')

or, more automated:

pd.date_range('2022-07-01', periods=20, freq='W-MON')

as string:

pd.date_range('2022-07-01', periods=20, freq='W-MON').strftime('%d/%m/%Y')

example:

      option1    option2     option3
0  2022-07-04 2022-07-04  04/07/2022
1  2022-07-11 2022-07-11  11/07/2022
2  2022-07-18 2022-07-18  18/07/2022
3  2022-07-25 2022-07-25  25/07/2022
...
16 2022-10-24 2022-10-24  24/10/2022
17 2022-10-31 2022-10-31  31/10/2022
18 2022-11-07 2022-11-07  07/11/2022
19 2022-11-14 2022-11-14  14/11/2022
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading