Turn pandas series to series of lists or numpy array to array of lists
<p>I have a series <code>s</code></p>

<pre><code>s = pd.Series([1, 2])
</code></pre>

<p>What is an efficient way to make <code>s</code> look like</p>

<pre><code>0    [1]
1    [2]
dtype: object
</code></pre>

<p>Here's one approach that extracts into array and extends to <code>2D</code> by introducing a new axis with <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.indexing.html#numpy.newaxis" rel="nofollow"><code>None/np.newaxis</code></a> -</p>

<pre><code>pd.Series(s.values[:,None].tolist())
</code></pre>

<p>Here's a similar one, but extends to <code>2D</code> by reshaping -</p>

<pre><code>pd.Series(s.values.reshape(-1,1).tolist())
</code></pre>

<p>Runtime test using <a href="http://stackoverflow.com/a/39797640/3293881"><code>@P-robot's setup</code></a> -</p>

<pre><code>In [43]: s = pd.Series(np.random.randint(1,10,1000))

In [44]: %timeit pd.Series(np.vstack(s.values).tolist()) # @Nickil Maveli's soln
100 loops, best of 3: 5.77 ms per loop

In [45]: %timeit pd.Series([[a] for a in s]) # @P-robot's soln
1000 loops, best of 3: 412 Âµs per loop

In [46]: %timeit s.apply(lambda x: [x]) # @mgc's soln
1000 loops, best of 3: 551 Âµs per loop

In [47]: %timeit pd.Series(s.values[:,None].tolist()) # Approach1
1000 loops, best of 3: 307 Âµs per loop

In [48]: %timeit pd.Series(s.values.reshape(-1,1).tolist()) # Approach2
1000 loops, best of 3: 306 Âµs per loop
</code></pre>

python pandas numpy