Python 在datatime上应用where函数[SQL like]

Python 在datatime上应用where函数[SQL like],python,pandas,Python,Pandas,我有这样一个数据集: Date/Time Byte 0 2015-04-02 10:44:31 1 1 2015-04-02 10:44:21 10 2 2015-04-02 11:01:11 2 3 2015-04-02 11:01:21 20 我希望打印与以下内容相关的所有行: 2015-04-02上午11时 我尝试了许多不同的解决方案,但没有结果 df是我的数据

我有这样一个数据集:

         Date/Time       Byte 
0 2015-04-02 10:44:31 1 1 2015-04-02 10:44:21 10 2 2015-04-02 11:01:11 2 3 2015-04-02 11:01:21 20

我希望打印与以下内容相关的所有行:

2015-04-02上午11时

我尝试了许多不同的解决方案,但没有结果 df是我的数据帧

为了使istance仅打印与11相关的流,我尝试了以下方法: res=df.loc[df['stamp'].hour==11]

有误: AttributeError:“Series”对象没有属性“hour”

如何提取与特定小时相关的所有行? 如何提取与特定日期的特定小时相关的所有行


谢谢,祝您愉快

如果时间戳存储为字符串,请在时间戳上使用pd.to_datetime

那你就可以了

df[df['a_date_col'].apply(lambda x: x.hour) == 11]
或者您可以使用.dt访问器:

df[df['a_date_col'].dt.hour == 11]

我尝试了第二个选项:df[df['a_date\u col'].dt.hour==11],但是python返回:AttributeError:'Series'对象没有属性'dt'@SilvestroDaniloGiordano您使用的熊猫是什么版本?这是一个相对较新的功能。