Filtering and comparing dates with Pandas

后端 未结 3 1869
花落未央
花落未央 2021-02-09 04:51

I would like to know how to filter different dates at all the different time levels, i.e. find dates by year, month, day, hour, minute and/or day. For example, how do I find all

3条回答
  •  伪装坚强ぢ
    2021-02-09 05:36

    You can filter your dataframe via boolean indexing like so:

    df.loc[df['timeStamp'].dt.year == 2014]
    df.loc[df['timeStamp'].dt.month == 5]
    df.loc[df['timeStamp'].dt.second == 4]
    df.loc[df['timeStamp'] == '2014-01-02']
    df.loc[pd.to_datetime(df['timeStamp'].dt.date) == '2014-01-02']
    

    ... and so on and so forth.

提交回复
热议问题