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>I think you can convert all values to <code>lists</code> and then create <code>Series</code>, but then lost indices:</p>

<pre><code>df = pd.DataFrame({'A':[1,2,3],
                   'B':[4,5,6],
                   'C':[7,8,9],
                   'D':[1,3,5],
                   'E':[5,3,6],
                   'F':[7,4,3]})

print (df)
   A  B  C  D  E  F
0  1  4  7  1  5  7
1  2  5  8  3  3  4
2  3  6  9  5  6  3

row_count = 1

print (df.iloc[row_count, range (2, 4)])
C    8
D    3
Name: 1, dtype: int64

dfnow = pd.Series([df.iloc[row_count,0]]  + df.iloc[row_count, range (2, 4)].tolist())
print (dfnow)
0    2
1    8
2    3
dtype: int64
</code></pre>

<hr>

<p>Or you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a>, then indices are column names:</p>

<pre><code>row_count = 1

a = df.iloc[row_count, range (2, 4)]
b = df.iloc[row_count, range (4, 6)]

print (a)
C    8
D    3
Name: 1, dtype: int64

print (b)
E    3
F    4
Name: 1, dtype: int64

print (pd.concat([a,b]))
C    8
D    3
E    3
F    4
Name: 1, dtype: int64
</code></pre>

<p>But if need add scalar (<code>a</code>), it is a bit complicated - need <code>Series</code>:</p>

<pre><code>row_count = 1

a = pd.Series(df.iloc[row_count, 0], index=[df.columns[0]])
b = df.iloc[row_count, range (2, 4)]
c = df.iloc[row_count, range (4, 6)]

print (a)
A    2
dtype: int64

print (b)
C    8
D    3
Name: 1, dtype: int64

print (c)
E    3
F    4
Name: 1, dtype: int64

print (pd.concat([a,b,c]))
A    2
C    8
D    3
E    3
F    4
dtype: int64
</code></pre>

python pandas