How to combine an index "prefix" to the data in a Pandas series? Does one create a numpy array?
<p>I have a pandas series:</p>

<pre><code>import pandas 
ser = pd.Series(...)
ser

idx1     23421535123415135
idx2     98762981356281343
idx3     394123942916498173
idx4     41234189756983411
...
idx50    123412938479283419
</code></pre>

<p>I would like to combined the index append to the front of each data row. The output I'm looking for is:</p>

<pre><code>idx1 23421535123415135
idx2 98762981356281343
idx3 394123942916498173
idx4 41234189756983411
...
idx50 123412938479283419
</code></pre>

<p>This could either be a pandas Series (where the array is naturally indexed) or a numpy array. </p>

<p>For a dataframe, in order to combine two columns, you use:</p>

<pre><code>df["newcolumn"] = df[['columnA','columnB']].astype(str).sum(axis=1)
</code></pre>

<p>but I'm confused how to accomplish this with a pandas series.</p>

<p>Say you start with your Series:</p>

<pre><code> In [34]: s = pd.Series(data=[1, 2], index=['idx0', 'idx1'])
</code></pre>

<p>Then you can do </p>

<pre><code>In [35]: t = s.reset_index()

In [36]: t['index'].astype(str) + ' ' + t[0].astype(str)
Out[36]: 
0    idx0 1
1    idx1 2
dtype: object
</code></pre>

<p>Note that if you don't need to introduce the space in between, it's shorter:</p>

<pre><code>In [37]: s.reset_index().astype(str).sum(axis=1)
Out[37]: 
0    idx01
1    idx12
dtype: object
</code></pre>

python arrays pandas numpy