converting a pandas date to week number

前端 未结 4 1649
轮回少年
轮回少年 2020-12-02 16:40

I would like to extract a week number from data in a pandas dataframe.

The date format is datetime64[ns]

I have normalized the date to remove the time from i

4条回答
  •  不思量自难忘°
    2020-12-02 17:23

    from datetime import date
    df_date = pd.DataFrame([date.today()],columns  = ['today'])
    print(df_date)
    #### Print Output ####
    #        today
    #0  2019-09-07
    df_date['weeknum'] = df_date.today.apply(lambda x:x.isocalendar()[1])
    print(df_date)
    #### Print Output ####
    #        today  weeknum
    #0  2019-09-07       36
    

提交回复
热议问题