# Load library
import pandas as pd

"""
Explanation: Title: Select Date And Time Ranges
Slug: select_date_and_time_ranges
Summary: How to select date and time ranges in Python.   
Date: 2017-09-11 12:00
Category: Machine Learning
Tags: Preprocessing Dates And Times  
Authors: Chris Albon
Preliminaries
End of explanation
"""


# Create data frame
df = pd.DataFrame()

# Create datetimes
df['date'] = pd.date_range('1/1/2001', periods=100000, freq='H')

"""
Explanation: Create pandas Series Time Data
End of explanation
"""


# Select observations between two datetimes
df[(df['date'] > '2002-1-1 01:00:00') & (df['date'] <= '2002-1-1 04:00:00')]

"""
Explanation: Select Time Range (Method 1)
Use this method if your data frame is not indexed by time.
End of explanation
"""


# Set index
df = df.set_index(df['date'])

# Select observations between two datetimes
df.loc['2002-1-1 01:00:00':'2002-1-1 04:00:00']

"""
Explanation: Select Time Range (Method 2)
Use this method if your data frame is indexed by time.
End of explanation
"""


