Wednesday, September 26, 2018

Python coding

Most often Data science professionals especially who use open source tools like python encounter issues related to date. Conversion to different format, short forms etc. This is an attempt to bring few of  the issues related to date in one window .
How to get the last 6 months from the current date  ->( format May 2018 )?
datelist=[ ]
datem = datetime.date.today().replace(day=1)
for i in range (7):
    x = datem + relativedelta(months=-i)
    x=datetime.datetime.strftime(x,'%b %Y')
    datelist.append(x)
del datelist[0]