如何根据 pandas 中的时间值过滤数据? [英] how to filter data based on time values in pandas?

查看:38
本文介绍了如何根据 pandas 中的时间值过滤数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python的新手.我正在研究pandas软件包,以分析工作负荷模式.我的数据框包含两列,分别是工作的开始时间和结束时间.我想在特定的开始时间和结束时间之间过滤数据帧的行.例如,上午7:00:00之后和下午18:00:00前.我尝试使用以下内容:

I am new to Python. I am working on pandas package to analyse the work load pattern. My dataframe contains two columns with start and end time of work. I would like to filter rows of dataframe between particular start time and end time. For e.g after 7:00:00 am and before 18:00:00 pm. I tried using the following :

(df['STime'] > '7:00:00') & (df['ETime'] < '18:00:00') 

但是它为所有行返回False.

But it returns False for all rows.

推荐答案

您正在比较值,这就是为什么您只获得False值的原因 将此表达式与数据框一起使用.

You are just comparing the values that's why you are getting only False values Use this expression with dataframe.

 df=df[(df['STime'] > '7:00:00') and (df['ETime'] < '18:00:00')]

这篇关于如何根据 pandas 中的时间值过滤数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆