且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 pandas 按月,日,年过滤

更新时间:2023-01-29 22:36:27

只要您的熊猫版本为0.15或更高版本,那么假设您的dtype已经是日期时间,以下操作将起作用:

So long as your pandas version is 0.15 or higher then the following would work assuming your dtype is already a datetime:

In [167]:

df[df.System_created.dt.day == 5]
Out[167]:
       Qty      System_created  Total
index                                
5        2 2014-11-05 11:15:47  21.76
6        1 2014-11-05 11:15:48   3.32

因此,基本上dt属性允许您访问日期时间的组成部分以执行您希望过滤的比较

So basically the dt attribute allows you to access the components of your datetime to perform the comparisons you desire for filtering