How to make a sequence dates in python?

Asked

Viewed 466 times

0

I need to create a date array of 2018-01-01, 2020-01-11, the dates being nay can be continuous (eg 2018-01-01, 2018-01-02, 2018-01-03...) and include the ends.

The closest I could get was:

import pandas as pd
date_list = pd.date_range(start='2018-01-01', end='2020-01-11', freq = '3M', closed= 'left')
date_list
Out[3]: 
DatetimeIndex(['2018-01-31', '2018-04-30', '2018-07-31', '2018-10-31',
           '2019-01-31', '2019-04-30', '2019-07-31', '2019-10-31'],
          dtype='datetime64[ns]', freq='3M')

However it did not include the extremities (2018-01-01, 2020-01-11).

  • 3

    If they should not be in sequence, how should they be? What is the full sequence you want to get?

1 answer

1


Márcio, see if this is what you need.

import pandas as pd
import datetime


dRan = pd.date_range(start ='2018-01-01', 

       end ='2020-01-11', periods = 13)   

res = dRan.strftime('%d/%m/%Y')

print(res) 

inserir a descrição da imagem aqui

  • The "M" parameter always considers the Last Index for the return. Try to adapt the "period" for your project. Any questions are here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.