python_筛选日期
生成日期 date_range
7.3
# 라이브러리를 임포트합니다.
import pandas as pd
# 데이터프레임을 만듭니다.
dataframe = pd.DataFrame()
# 创建datetime
dataframe['date'] = pd.date_range('1/1/2001', periods=100000, freq='H')
dataframe
# 두 datetime 사이의 샘플을 선택합니다. 筛选日期
dataframe[(dataframe['date'] > '2002-1-1 01:00:00') &
(dataframe['date'] <= '2002-1-1 04:00:00')]
date
8762 2002-01-01 02:00:00
8763 2002-01-01 03:00:00
8764 2002-01-01 04:00:00
筛选日期
# 设置索引
dataframe = dataframe.set_index(dataframe['date'])
#筛选日期
dataframe.loc['2002-1-1 01:00:00':'2002-1-1 04:00:00']
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