title: How to set all elements of one column of dataframe to arrays?
body: <p>I just want to know how to set all elements of one column of dataframe to arrays in Pandas.</p>
  
  <p>Just like this, column one and two</p>
  
  <pre><code>  a b c d   one    two
  0 1 2 3 4 [1, 2] [1, 2]
  1 2 2 3 4 [2, 2] [2, 2]
  2 3 2 3 4 [3, 2] [3, 2]
  </code></pre>
  
  <p>I have tried, but only in this way:</p>
  
  <pre><code>d['one']=[[1,2],[2,2],[3,2]]
  </code></pre>
  
  <p>And if I want to use the numpy array instead of python built-in array, like:</p>
  
  <pre><code>d['one']=np.array([[1,2],[2,2],[3,2]])
  </code></pre>
  
  <p>It comes to:</p>
  
  <pre><code>  a b c d one  two
  0 1 2 3 4  1 [1, 2]
  1 2 2 3 4  2 [2, 2]
  2 3 2 3 4  3 [3, 2]
  </code></pre>
  
  <p>Or I want to set a column to one same array at one time, for example,</p>
  
  <pre><code>d['one']=[1,2], or d['c']=[1,2]
  </code></pre>
  
  <p>Like this:</p>
  
  <pre><code>  a b c d   one    two
  0 1 2 3 4 [1, 2] [1, 2]
  1 2 2 3 4 [1, 2] [2, 2]
  2 3 2 3 4 [1, 2] [3, 2]
  </code></pre>
  
  <p>It has error:</p>
  
  <p><em>ValueError: Length of values does not match length of index</em></p>
  
  <p>Also, If I want to change the values of column b to arrays according to conditions, I found I can't do this. Because I need to use conditions, so there exists a sequence of the assignment operations, which means I can't set the column to arrays like this:</p>
  
  <pre><code>d['b']=[[1,2],[6,7],[6,7]]
  </code></pre>
  
  <p>, at one time. I need to do it step by step.</p>
  
  <p>For example, set the column b to [1,2] where a=1 firstly, </p>
  
  <pre><code>d.loc[d['a']==1,'b']=[1,2]
    a     b c d   one    two
  0 1 [1,2] 3 4 [1, 2] [1, 2]
  1 2     2 3 4 [2, 2] [2, 2]
  2 3     2 3 4 [3, 2] [3, 2]
  </code></pre>
  
  <p>Then set the column b to [6,7],[6,7] where a=2 or a=3, </p>
  
  <pre><code>d.loc[(d['a']==2)|(d['a']==3),'b']=[6,7]
    a    b  c d   one    two
  0 1 [1,2] 3 4 [1, 2] [1, 2]
  1 2 [6,7] 3 4 [2, 2] [2, 2]
  2 3 [6,7] 3 4 [3, 2] [3, 2]
  </code></pre>
  
  <p>The former one has error:</p>
  
  <p><em>Must have equal len keys and value when setting with an iterable</em></p>
  
  <p>If I do it in another way:</p>
  
  <pre><code>d['b'][0]=[1,2]
  </code></pre>
  
  <p>Also error:</p>
  
  <p><em>ValueError: setting an array element with a sequence.</em></p>
  
  <p>And the latter one comes to:</p>
  
  <pre><code>  a b c d   one    two
  0 1 2 3 4 [1, 2] [1, 2]
  1 2 6 3 4 [2, 2] [2, 2]
  2 3 7 3 4 [3, 2] [3, 2]
  </code></pre>
  
  <p>, which is not I want, so how to write to achieve this effect?</p>
  
  <p>To sum up,</p>
  
  <ol>
  <li><p>How can I use numpy array to achieve this? How can I set a column to one same array at one time?</p></li>
  <li><p>How can I change the values of a column to arrays according to conditions?</p></li>
  </ol>