Iterating through a range of dates in Python

后端 未结 23 1803
醉酒成梦
醉酒成梦 2020-11-22 04:40

I have the following code to do this, but how can I do it better? Right now I think it\'s better than nested loops, but it starts to get Perl-one-linerish when you have a ge

23条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 04:59

    You can generate a series of date between two dates using the pandas library simply and trustfully

    import pandas as pd
    
    print pd.date_range(start='1/1/2010', end='1/08/2018', freq='M')
    

    You can change the frequency of generating dates by setting freq as D, M, Q, Y (daily, monthly, quarterly, yearly )

提交回复
热议问题