How to calculate difference between Dates in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to calculate difference between Dates in Python?

How to calculate difference between Dates in Python?

This recipe helps you calculate difference between Dates in Python

0
In [1]:
## How to claculate difference between Dates in Python 
def Kickstarter_Example_42():
    print()
    print(format('How to claculate difference between Dates in Python',
                 '*^82'))
    import warnings
    warnings.filterwarnings("ignore")

    # Load library
    import pandas as pd

    # Create data frame
    df = pd.DataFrame()

    # Create two datetime features
    df['Date1'] = [pd.Timestamp('01-01-2017'),
                     pd.Timestamp('01-04-2017')]
    df['Date2']    = [pd.Timestamp('01-01-2017'),
                     pd.Timestamp('01-06-2017')]

    # Calculate Difference (Method 1)
    print(df['Date2'] - df['Date1'])

    # Calculate Difference (Method 2)
    print(pd.Series(delta.days for delta in (df['Date2'] - df['Date1'])))

Kickstarter_Example_42()
***************How to claculate difference between Dates in Python****************
0   0 days
1   2 days
dtype: timedelta64[ns]
0    0
1    2
dtype: int64

Relevant Projects

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

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.

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.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

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.