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>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mask.html" rel="nofollow"><code>mask</code></a>:</p>

<pre><code>data = pd.DataFrame({'day_of_week':[0,1,2,3,4,5,6]})

#original column to new, add 1
data['if_Weekday'] = data['day_of_week'] + 1

#map days if necessary
days = {0:'Mon', 1: 'Tues', 2:'Wed', 3:'Thurs', 4:'Fri', 5:'Sat', 6:'Sun'}
data['day_of_week'] = data['day_of_week'].map(days)

#correct weekend days
data['if_Weekday'] = data['if_Weekday'].mask(data['if_Weekday'] &gt;= 6, 0)

print (data)
  day_of_week  if_Weekday
0         Mon           1
1        Tues           2
2         Wed           3
3       Thurs           4
4         Fri           5
5         Sat           0
6         Sun           0
</code></pre>

python pandas numpy multiple-columns dayofweek