Pandas: select all dates with specific month and day

后端 未结 2 1294
天涯浪人
天涯浪人 2020-12-06 16:27

I have a dataframe full of dates and I would like to select all dates where the month==12 and the day==25 and add replace the zero in the xmas column with a 1.<

2条回答
  •  一个人的身影
    2020-12-06 17:08

    Pandas Series with datetime now behaves differently. See .dt accessor.

    This is how it should be done now:

    df.loc[(df['date'].dt.day==25) & (cust_df['date'].dt.month==12), 'xmas'] = 1
    

提交回复
热议问题