assign series values based on index
<p>having a simple series:</p>

<pre><code>&gt;&gt;&gt; s = pd.Series(index=pd.date_range('2016-09-01','2016-09-05'))
&gt;&gt;&gt; s

2016-09-01   NaN
2016-09-02   NaN
2016-09-03   NaN
2016-09-04   NaN
2016-09-05   NaN
Freq: D, dtype: float64
</code></pre>

<p>Am I able to set series values based on its index? 
Let's say, I want to set series values to dayofweek of corresponding index entry. Of course, I can accomplish it easily by constructing series from scratch:</p>

<pre><code>&gt;&gt;&gt; dr = pd.date_range('2016-09-01','2016-09-05')
&gt;&gt;&gt; s = pd.Series(data=dr.dayofweek, index=dr)
&gt;&gt;&gt; s

2016-09-01    3
2016-09-02    4
2016-09-03    5
2016-09-04    6
2016-09-05    0
Freq: D, dtype: int32
</code></pre>

<p>I am also able to accomplish it using dataframe: <code>df['old_column'] = df.index.dayofweek</code>. Is it possible to set series in similar manner (using the only "column" series have)? <code>.apply()</code> and <code>.map()</code> methods seem as no help, since they do not work with index values...</p>

<p>You can do it like this:</p>

<pre><code>s[s.index] = s.index.dayofweek

s
Out: 
2016-09-01    3
2016-09-02    4
2016-09-03    5
2016-09-04    6
2016-09-05    0
Freq: D, dtype: int32
</code></pre>

python pandas series