Embedding a range in a pandas series
<p>I have a table of 14 columns and I want to pull select ones into a new dataframe. 
Let's say I want column 0 then column 8-14</p>

<pre><code>  dfnow = pd.Series([df.iloc[row_count,0], \
                    df.iloc[row_count,8], \
                    df.iloc[row_count,9], \
                    ....
</code></pre>

<p>Works but seems clumsy</p>

<p>I'd like to write </p>

<pre><code>  dfnow = pd.Series([df.iloc[row_count,0], \
          df.iloc[row_count, range (8, 14)]])
</code></pre>

<p>But this throws a ValueError: Wrong number of items passed</p>

<p>Now, from the answer below, I know I can create two separate sereis and concatenate them, but that seems a little sub-optimal as well. </p>

<p><a href="https://stackoverflow.com/questions/12504493/adding-pandas-series-with-different-indices-without-getting-nans">Adding pandas Series with different indices without getting NaNs</a></p>

<p>Is that what you want?</p>

<pre><code>In [52]: df = pd.DataFrame(np.arange(30).reshape(5,6), columns=list('abcdef'))

In [53]: df
Out[53]:
    a   b   c   d   e   f
0   0   1   2   3   4   5
1   6   7   8   9  10  11
2  12  13  14  15  16  17
3  18  19  20  21  22  23
4  24  25  26  27  28  29

In [54]: df[[0,2,4]]
Out[54]:
    a   c   e
0   0   2   4
1   6   8  10
2  12  14  16
3  18  20  22
4  24  26  28
</code></pre>

<p>concatenating (reshaping) columns <code>0</code>,<code>2</code>,<code>4</code> into single series:</p>

<pre><code>In [68]: df[[0,2,4]].values.T.reshape(-1,)
Out[68]: array([ 0,  6, 12, 18, 24,  2,  8, 14, 20, 26,  4, 10, 16, 22, 28])

In [69]: pd.Series(df[[0,2,4]].values.T.reshape(-1,))
Out[69]:
0      0
1      6
2     12
3     18
4     24
5      2
6      8
7     14
8     20
9     26
10     4
11    10
12    16
13    22
14    28
dtype: int32
</code></pre>

python pandas