Python 3.x 仅保留日期为整小时的数据帧行

Python 3.x 仅保留日期为整小时的数据帧行,python-3.x,pandas,pandas-groupby,Python 3.x,Pandas,Pandas Groupby,我有一个数据帧,数据间隔为15米 股票全名开盘价高低收盘价日期 AAPL苹果公司206.3940 206.5050 206.0100 206.3040 2242259.0 2019-09-03 09:45:00 1 AAPL苹果公司206.3200 206.9500 206.2960 206.6900 1094447.0 2019-09-03 10:00:00 2 AAPL苹果公司206.6700 206.6700 204.3800 204.4200 1837739.0 2019-09-03 1

我有一个数据帧,数据间隔为15米

股票全名开盘价高低收盘价日期
AAPL苹果公司206.3940 206.5050 206.0100 206.3040 2242259.0 2019-09-03 09:45:00
1 AAPL苹果公司206.3200 206.9500 206.2960 206.6900 1094447.0 2019-09-03 10:00:00
2 AAPL苹果公司206.6700 206.6700 204.3800 204.4200 1837739.0 2019-09-03 10:15:00
3 AAPL苹果公司204.4282 205.0963 204.4156 204.8282 1199631.0 2019-09-03 10:30:00
4 AAPL苹果公司204.8174 205.4500 204.5300 205.1924 959709.0 2019-09-03 10:45:00


问题是,如何只保留整小时的行数?(例如2019-09-03 10:00:00)

第一个想法是测试分钟和秒数是否为
0

df['date'] = pd.to_datetime(df['date'])

df1 = df[df['date'].dt.minute.eq(0) & df['date'].dt.second.eq(0)]
或按原始列按小时进行比较:

df1 = df[df['date'].dt.floor('H').eq(df['date'])]
print (df1)
  stock    fullname    open    high      low   close     volume  \
1  AAPL  Apple Inc.  206.32  206.95  206.296  206.69  1094447.0   

                 date  
1 2019-09-03 10:00:00  

第一个想法是测试分和秒是否为
0

df['date'] = pd.to_datetime(df['date'])

df1 = df[df['date'].dt.minute.eq(0) & df['date'].dt.second.eq(0)]
或按原始列按小时进行比较:

df1 = df[df['date'].dt.floor('H').eq(df['date'])]
print (df1)
  stock    fullname    open    high      low   close     volume  \
1  AAPL  Apple Inc.  206.32  206.95  206.296  206.69  1094447.0   

                 date  
1 2019-09-03 10:00:00  
让我们试试

df1 = df[df['date'].dt.strftime('%M:%S').eq('00:00')].copy()
让我们试试

df1 = df[df['date'].dt.strftime('%M:%S').eq('00:00')].copy()