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:



EDA

EDA On New York Clinic Data/Attendees Data (Project)


EDA: Exploratory Data Analysis.

    First, we import CSV files. To import them, CSV files should be libraries.

How to import CSV file in libraries:
1. Click "+" dropdown, select "From Computer"  to upload file in your library.




2. Now you will be able to read CSV files, by simply writing below commands:

3. To find the name of the column:

4. To put the columns inside the list:

5. To select only two columns:

6. To find data where "month"  is "12/90":

7. To find total no. of all the columns:

8. To find the location of "1/86"  and "market"  to be -0.061134 :



9. Use of Group By:- To group by "market" and cout of "month":




10. To find all the "market" and count of "month" : 


11. Melt is used to convert a bunch of columns into single row.



Join Example

Join Example


1. Create DataFrame 1:


2. Create DataFrame 2:


3. Inner Join:


4. Outer Join:


5. Left-Outer Join:


6. Right-Outer Join:


Try out below as well:

1.


2.  Create another two DataFrames:
DataFrame 1:

DataFrame 2: 

3.

4. Concat() is similar to Union and Union All in SQL.



Some other experimented try out:

1.  Create DataFrame with the following conditions:

2. stack the DataFrame:

3. Apply conditions as shown below:
4. unstack the dataframe:

This is the basic difference between stack() and unstack().