Recipe: How to select DateTime within a range in Python?
DATA MUNGING PYTHON DATETIME DATA CLEANING 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()
    print(format('How to select DateTime within a range in Python','*^82'))
    import warnings
    warnings.filterwarnings("ignore")

    # 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'])
Kickstarter_Example_48()
*****************How to select DateTime within a range in Python******************

                                   date
date
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


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from HvH
1 developer from Sonata Software
1 developer from Altimetrik
1 developer from KPMG
1 developer from Vodafone
1 developer from ANAC
1 developer from LTI
1 developer from YASH Technologies
1 developer from Embicon
1 developer from MudraCircle