How to filter by month, day, year with Pandas

后端 未结 1 1967
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 23:49

I create the DataFrame with:

df = pandas.read_csv(\"data.csv\", sep=\';\', parse_dates = 1, dayfirst = True)

I then get the following results:

相关标签:
1条回答
  • 2020-12-07 00:27

    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
    

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

    0 讨论(0)
提交回复
热议问题