Pandas Dataframe, assign values to day of the week. Feature extraction
<p>I am extracting features to look for the weekdays. What I have so far is this:</p>

<pre><code>days = {0:'Mon', 1: 'Tues', 2:'Wed', 3:'Thurs', 4:'Fri', 5:'Sat', 6:'Sun'}
data['day_of_week'] = data['day_of_week'].apply(lambda x: days[x])
data['if_Weekday'] = np.where( (data['day_of_week'] == 'Mon') | (data['day_of_week'] == 'Tues') | (data['day_of_week'] == 'Wed') | (data['day_of_week'] == 'Thurs') | (data['day_of_week'] == 'Friday'), '1', '0')
</code></pre>

<p>This code will assign Mon-Fri as a <code>1</code> and Sat-Sun as a <code>0</code>. However, I would like to assign different values for the weekdays. For instance, Mon = 1, Tues = 2, Wed = 3, Thurs = 4, Fri = 5 and Sat and Sun should both equal 0.</p>

<p>Any help would be much appreciated.  </p>

<p>OK I think the easiest thing here is to use <code>np.where</code> to test whether the weekday is greater than or equal to 5 and if so assign <code>0</code>, else return the weekday value and add <code>1</code> to it:</p>

<pre><code>In [21]:
df['is_weekday'] = np.where(df['weekday'] &gt;= 5, 0, df['weekday'] + 1)
df
Out[21]:
       dates  weekday  is_weekday
0 2016-01-01        4           5
1 2016-01-02        5           0
2 2016-01-03        6           0
3 2016-01-04        0           1
4 2016-01-05        1           2
5 2016-01-06        2           3
6 2016-01-07        3           4
7 2016-01-08        4           5
8 2016-01-09        5           0
9 2016-01-10        6           0
</code></pre>

python pandas numpy multiple-columns dayofweek