How to introduce LAG time in Python?

How to introduce LAG time in Python?

How to introduce LAG time in Python?

This recipe helps you introduce LAG time in Python

This python source code does the following : 1. Creates your own time series data. 2. Implements Lag time function("shift")for filling nan values. 3. Displays the final result.
In [1]:
## How to introduce LAG time in Python 
def Kickstarter_Example_46():
    print(format('How to introduce LAG time in Python','*^82'))
    import warnings

    # Load library
    import pandas as pd

    # Create data frame
    df = pd.DataFrame()

    # Create data
    df['dates'] = pd.date_range('11/11/2016', periods=5, freq='D')
    df['stock_price'] = [1.1,2.2,3.3,4.4,5.5]

    # Lag Time Data By One Row
    df['previous_days_stock_price'] = df['stock_price'].shift(1)

    # Show data frame
    print(); print(df)

    # Lag Time Data By Two Rows
    df['previous_days_stock_price'] = df['stock_price'].shift(2)

    # Show data frame
    print(); print(df)

***********************How to introduce LAG time in Python************************

       dates  stock_price  previous_days_stock_price
0 2016-11-11          1.1                        NaN
1 2016-11-12          2.2                        1.1
2 2016-11-13          3.3                        2.2
3 2016-11-14          4.4                        3.3
4 2016-11-15          5.5                        4.4

       dates  stock_price  previous_days_stock_price
0 2016-11-11          1.1                        NaN
1 2016-11-12          2.2                        NaN
2 2016-11-13          3.3                        1.1
3 2016-11-14          4.4                        2.2
4 2016-11-15          5.5                        3.3

Relevant Projects

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Data Science Project-All State Insurance Claims Severity Prediction
Data science project in R to develop automated methods for predicting the cost and severity of insurance claims.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Anomaly Detection Using Deep Learning and Autoencoders
Deep Learning Project- Learn about implementation of a machine learning algorithm using autoencoders for anomaly detection.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.