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

<pre><code>In[8]:ser
Out[8]: 
idx0     23421535123415135
idx1     98762981356281343
idx2    394123942916498173
idx3     41234189756983411
dtype: int64

In[9]:ser=pd.Series(ser.index.astype(str).str.cat(ser.astype(str),' '))

In[10]:ser
Out[10]: 
0     idx0 23421535123415135
1     idx1 98762981356281343
2    idx2 394123942916498173
3     idx3 41234189756983411
dtype: object
</code></pre>

python arrays pandas numpy