Friday, November 1, 2019

Time Series

Time Series


         Time Series is a collection of data points collected at constant time intervals. These are analyzed to determine the long term trend so as to forecast the future or perform some other form of analysis. Import is required for DateTime. DateTime is in the string.

1. 



2. To give today's date in String:

3. Difference of datetime, use subtraction " - ":

4. To get the difference in seconds:


5. Convert String into DateTime:

6. Another DateTime format you can use:




#Difference between strptime and strftime :
  • This is what DateTime looks like-  (2011,10,29,20,30,21)
    To someone who is quite familiar with this format, what's written up there is no immediately intuitive. So one would probably go for Sun, 29 October, 2011. This what strftime is used for.
  • strftime(): It converts an object to a string according to a given format.
                      Type of method: Instance method.
                      Method of: date, datetime, time.
                     
    Syntax: strftime(format).
  • strptime(): It converts a string into a datetime object given a corresponding format.
                      Type of method: Class method.
                      Method of: dateime.
                      Syntax: strptime(date_string, format).

#Converting big list of string to DateTime: If we got big list of string which is DateTime and want to convert to DateTime format, then take the x(which has a list) and give list where everything is in DateTime format. See below:


     'Y' denotes 4-digit year.
     'y' denotes 2-digit year.


#Parse: It's a DateTime utility which makes the best guess based on the internal algorithm of the DateTime. We don't have to tell how DateTime is stored.


#Series in DateTime: Give random 4 numbers and give date range from 1/1/2000 and give frequency as monthly, with period 4. See below:
      Here randn() and period value should be same, otherwise, it will through a bug.
      Frequency: M denotes Monthly.
                         Q denotes Quarterly.
                         A denotes Annual.
                         D denotes Day
                         90T denotes 90Days


#Shifts(): It moves things up and down.

  1. This shifts month down:

  2. This shifts month up:

  3. This shifts as per the calculation:

  4. This shifts as per frequency:
     
      Also try ut with: 
     freq='D' and  freq='90T'
  5. To user Day(), import Day and MonthEnd. This prints the date 3 days ahead.



  6. Day() gives 1 day.

  7. This takes the end of the month i.e 30 from 20.

  8. This takes one month ahead and takes to December(12).

#Resample(): It is similar to groupby method. It is necessary when we are given a data set recorded in some time interval and we want to change the time interval to something else. For Example, We could aggregate monthly data into yearly data or unsample hourly data into minute-by-minute data.


--------Try out -------------

     


For more on DateTime, you can follow below url:



No comments:

Post a Comment