Separate working days from non-working days based on a column of dates

Separate working days from non-working days based on a column of dates

Need to distinguish between working days and non-working days based on a given list of dates

insert image description here

You can first count the day of the week corresponding to the date:

df_1['星期'] = ''
for i in range(1464):
    df_1['星期'][i] = datetime.strptime(df_1['date'][i], "%Y-%m-%d").weekday()
df_1

insert image description here

But this method corresponds to {0: Monday, 1: Tuesday, 2: Wednesday, 3: Thursday, 4: Friday, 5: Saturday, 6: Sunday}

working days:

df_1_weekday =df_road1[(df_road1['星期'] >= 0 ) & (df_road1['星期']<= 4 )]

结果如下:

![在这里插入图片描述](https://img-blog.csdnimg.cn/dda899fa54864ad1b7185a25c9f79af8.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYml1Yml16aOe6LW3,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)

Guess you like

Origin blog.csdn.net/weixin_43697614/article/details/122968164