title: Inserting list into a cell - why does loc ACTUALLY work here?
body: <p>We are aware that the standard method of setting a single cell is using <code>at</code> or <code>iat</code>. However, I noticed some interesting behaviour I was wondering if anyone could rationalise. </p>
  
  <p>In solving <a href="https://stackoverflow.com/questions/26483254/python-pandas-insert-list-into-a-cell/">this question</a>, I come across some weird behaviour of <code>loc</code>.</p>
  
  <pre><code># Setup.
  
  pd.__version__
  # '0.24.0rc1'
  
  df = pd.DataFrame({'A': [12, 23], 'B': [['a', 'b'], ['c', 'd']]})
  df
      A       B
  0  12  [a, b]
  1  23  [c, d]
  </code></pre>
  
  <p>To set cell (1, 'B'), it suffices to do this with at, like <code>df.at[1, 'B'] = ...</code>. But with loc, I initially tried this, which did not work:</p>
  
  <pre><code>df.loc[1, 'B'] = ['m', 'n', 'o', 'p'] 
  # ValueError: Must have equal len keys and value when setting with an iterable
  </code></pre>
  
  <p>So, I tried (which also failed)</p>
  
  <pre><code>df.loc[1, 'B'] = [['m', 'n', 'o', 'p']]
  # ValueError: Must have equal len keys and value when setting with an ndarray
  </code></pre>
  
  <p>I thought <code>loc</code> would also somehow be able to take nested lists here. In a bizarre turn of events, <em>this</em> code worked:</p>
  
  <pre><code>df.loc[1, 'B'] = [['m'], ['n'], ['o'], ['p']]
  df
  
      A             B
  0  12        [a, b]
  1  23  [m, n, o, p]
  </code></pre>
  
  <p>Why does <code>loc</code> work this way? Additionally, if you add another element to any of the lists, it flops:</p>
  
  <pre><code>df.loc[1, 'B'] = [['m'], ['n'], ['o'], ['p', 'q']]
  # ValueError: Must have equal len keys and value when setting with an iterable
  </code></pre>
  
  <p>Empty lists don't work either. It seems pointless to have to nest each element in its own list. </p>
  
  <p>Why does <code>loc</code> do this? Is this documented behaviour, or a bug?</p>