Adding arrays to dataframe column
<p>Let's assume I have this dataframe <code>df</code>:</p>

<pre><code>   'Location'  'Rec ID'  'Duration'
0     Houston       126          17
1     Chicago       338        19.3
</code></pre>

<p>I would like to add a column with arrays corresponding to my recordings like:</p>

<pre><code>   'Location'  'Rec ID'  'Duration'                           'Rec'
0     Houston       126          17    [0.2, 0.34, 0.45, ..., 0.28]
1     Chicago       338        19.3    [0.12, 0.3, 0.41, ..., 0.39]
</code></pre>

<p>When I do the <code>df.set_value()</code> command I get the following error:</p>

<p><strong><em>ValueError: setting an array element with a sequence.</em></strong></p>

<p>I think the easiest is to assign <code>list</code> of <code>lists</code>, only you need same length of <code>lists</code> as <code>length</code> of <code>DataFrame</code>:</p>

<pre><code>arr = [[0.2, 0.34, 0.45, 0.28], [0.12, 0.3, 0.41, 0.39]]
print (arr)
[[0.2, 0.34, 0.45, 0.28], [0.12, 0.3, 0.41, 0.39]]

print (len(arr))
2
print (len(df))
2

df["'Rec'"] = arr
print (df)
   'Location'     'Rec  ID'  'Duration'                    'Rec'
0           0  Houston  126        17.0  [0.2, 0.34, 0.45, 0.28]
1           1  Chicago  338        19.3  [0.12, 0.3, 0.41, 0.39]
</code></pre>

<hr>

<p>If use <code>numpy array</code>, first convert <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tolist.html" rel="nofollow"><code>tolist</code></a>:</p>

<pre><code>arr = np.array([[0.2, 0.34, 0.45, 0.28], [0.12, 0.3, 0.41, 0.39]])
print (arr)
[[ 0.2   0.34  0.45  0.28]
 [ 0.12  0.3   0.41  0.39]]

df["'Rec'"] = arr.tolist()

print (df)
   'Location'     'Rec  ID'  'Duration'                    'Rec'
0           0  Houston  126        17.0  [0.2, 0.34, 0.45, 0.28]
1           1  Chicago  338        19.3  [0.12, 0.3, 0.41, 0.39]
</code></pre>

python arrays pandas dataframe