Python Gets the data for the previous 12 months, and Python gets the data for the year before the current time,

Source: Internet
Author: User

#Python implementations get the current time 12 months ago every month#Assuming the current time is September 25, 2016.#to get the time now is equal to September 25, 2016now =Datetime.datetime.now ()#get this year's time (year) get the today_year equals 2016Today_year =Now.year#this year's time minus 1, get last year's time. Last_year equalslast_year = Int (now.year)-1#get the time of this year's every month. Today_year_months equals 1 2 3 4 5 6 7 8 9,Today_year_months = Range (1,now.month+1)#get last year's every month time last_year_months equals tenLast_year_months = Range (now.month+1, 13)#define the data for the list last yearData_list_lasts = []#get a list of last year's time clip months through a for loop#go through the list of last month forLast_year_monthinchlast_year_months:#define Date_list last year plus last year's every monthDate_list ='%s-%s'%(Last_year, Last_year_month)#get a list of last year through the function appenddata_list_lasts.append (date_list) data_list_todays= []#get a list of this year's time clip month through A for loop#go through the list of the months of the year forToday_year_monthinchtoday_year_months:#define Date_list last year plus this year's every monthData_list ='%s-%s'%(Today_year, Today_year_month)#get a list of this year through the function appenddata_list_todays.append (data_list)#last year's time data plus this year's time data get the month time listData_year_month = data_list_lasts +Data_list_todaysdata_year_month.reverse ()

Program run process picture

Python Gets the data for the previous 12 months, and Python gets the data for the year before the current time,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.