How to select DateTime within a range in Python?

How to select DateTime within a range in Python?

How to select DateTime within a range in Python?

This recipe helps you select DateTime within a range in Python

In [1]:
## How to select DateTime within a range in Python 
def Kickstarter_Example_48():
    print(format('How to select DateTime within a range in Python','*^82'))
    import warnings

    # Load library
    import pandas as pd
    # Create data frame
    df = pd.DataFrame()
    # Create datetimes
    df['date'] = pd.date_range('15/12/1999', periods=100000, freq='H')
    # Set index
    df = df.set_index(df['date'])
    # Select observations between two datetimes
    print(); print(df.loc['2002-1-1 01:00:00':'2002-1-1 07:00:00'])
*****************How to select DateTime within a range in Python******************

2002-01-01 01:00:00 2002-01-01 01:00:00
2002-01-01 02:00:00 2002-01-01 02:00:00
2002-01-01 03:00:00 2002-01-01 03:00:00
2002-01-01 04:00:00 2002-01-01 04:00:00
2002-01-01 05:00:00 2002-01-01 05:00:00
2002-01-01 06:00:00 2002-01-01 06:00:00
2002-01-01 07:00:00 2002-01-01 07:00:00

Relevant Projects

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

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

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

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.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

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.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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