title: Replace nan cells with lists in Pandas dataframe
body: <p>I have the following Pandas dataframe:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">index</th>
  <th style="text-align: left;">title</th>
  <th style="text-align: center;">Open</th>
  <th style="text-align: center;">Close</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">2009-02-13</td>
  <td style="text-align: left;">[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...</td>
  <td style="text-align: center;">7933.000000</td>
  <td style="text-align: center;">7850.410156</td>
  </tr>
  <tr>
  <td style="text-align: center;">2009-02-14</td>
  <td style="text-align: left;">[613, 6294, 19, 251, 1463, 0, 0, 0, 0, 0, 0, 0...</td>
  <td style="text-align: center;">NaN</td>
  <td style="text-align: center;">NaN</td>
  </tr>
  <tr>
  <td style="text-align: center;">2009-02-17</td>
  <td style="text-align: left;">NaN</td>
  <td style="text-align: center;">7845.629883</td>
  <td style="text-align: center;">7552.600098</td>
  </tr>
  <tr>
  <td style="text-align: center;">2009-02-18</td>
  <td style="text-align: left;">NaN</td>
  <td style="text-align: center;">7546.350098</td>
  <td style="text-align: center;">7555.629883</td>
  </tr>
  <tr>
  <td style="text-align: center;">2009-02-19</td>
  <td style="text-align: left;">NaN</td>
  <td style="text-align: center;">7555.229980</td>
  <td style="text-align: center;">7465.950195</td>
  </tr>
  <tr>
  <td style="text-align: center;">...</td>
  <td style="text-align: left;">...</td>
  <td style="text-align: center;">...</td>
  <td style="text-align: center;">...</td>
  </tr>
  <tr>
  <td style="text-align: center;">2020-06-07</td>
  <td style="text-align: left;">[29, 68, 245, 3496, 62, 32, 20, 9, 11, 141, 32...</td>
  <td style="text-align: center;">NaN</td>
  <td style="text-align: center;">NaN</td>
  </tr>
  <tr>
  <td style="text-align: center;">2020-06-08</td>
  <td style="text-align: left;">[898, 30, 22, 1739, 47, 733, 8, 1182, 0, 0, 0,...</td>
  <td style="text-align: center;">27232.929688</td>
  <td style="text-align: center;">27572.439453</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>where the title column is an indexed tokenization of news titles. I cannot discard the NaN rows because they will be relevant for later processing. Instead, I want to make replace NaN values with lists of zeros of the same size of the not-NaN cells.</p>
  <p>I created a zeros list with:</p>
  <pre><code>max_wid = dataframe[&quot;title&quot;].map(lambda x: len(x)).max()
  zeros = np.zeros(max_wid, dtype=int).tolist()
  
  </code></pre>
  <p>I managed to assign the list in the first row with <code>.at</code> but it's not feasible to replace all rows manually, although it's the only tip I found online.</p>
  <p>I've tried using <code>.loc[dataframe.title.isnull(), &quot;title&quot;] = zeros</code> but it will return a <code> ValueError: cannot set using a multi-index selection indexer with a different length than the value</code>.</p>
  <p>I thought of using itertuples but it doesn't allow to set attributes and iterrows is discouraged.</p>
  <p>Any help is extremely appreciated.</p>
  <h2>EDIT</h2>
  I found an inefficient and inelegant solution by doing this:
  <pre><code>zeros = np.zeros(max_wid, dtype=int).tolist()
  dataframe[&quot;isna&quot;] = dataframe.title.isna()
  check = dataframe[&quot;isna&quot;].values
  title = dataframe[&quot;title&quot;].values
  test = np.empty((dataframe.shape[0]), dtype=object)
  
  for i,v in enumerate(test):
    if check[i] == True:
      test[i] = zeros
    else:
      test[i] = title[i]
  
  dataframe[&quot;title&quot;] = test.tolist()
  dataframe.drop(&quot;isna&quot;, axis=1, inplace=True)
  </code></pre>
  <p>If anyone can come up with a more optimized solution, I'll still appreciate it a lot!</p>