Select weekends and weekdays by weekday() in python

I have the following data:

2010-01-01 00:00:00 327 2010-01-01 01:00:00 237 2010-01-01 02:00:00 254 ... 

I can select different data by month but I would like to select data from weekdays and data from weekends. How could it be possible to do it by using weekday function? I have performed something like this but it does not work.

data['Month'] = data['Timestamp'].dt.month summer = (data.Month >=6) & (data.Month <=8)  data['WEEKDAY'] = ((pd.DatetimeIndex(data.index).dayofweek) // 5 == 1).astype(float) 
Add Comment
1 Answer(s)

Use:

data['WEEKDAY'] = data.Timestamp.dt.dayofweek 

0 is Monday. Next mark weekends as 1 in column WEEKEND:

data['WEEKEND'] = np.where(data.Timestamp.dt.dayofweek.isin([5,6]), 1, 0) 

To separate into 2 dataframes:

weekends = data[data['WEEKEND']==1] workdays = data[data['WEEKEND']!=1] 
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.