title: Python/Pandas: How do I combine two DataFrames, where one of the frames shall be a DataFrame within a cell of the other frame?
body: <p>I have two pandas DataFrames. Both DataFrames are time series with one common column (let's call it batchNumber) of the following structure:</p>
  
  <pre><code>[time = index, batchNumber, valueColumn, other fields]
  </code></pre>
  
  <p>The first DataFrame comprises one row per batchNumber, the second DataFrame comprises many rows per batchNumber, each row with an individual time step.</p>
  
  <p>I would like to combine (on purpose I avoid "join" here as I am not sure if this would be the right technique) these two frames into one having a structure:</p>
  
  <pre><code>[time1, batchNumber1 = batchNumber2, value1, [(time2[0], value2[0]), (time[1], value[1]), (time[2], value[2]), ..., (time[N], value[N])], other fields1]
  </code></pre>
  
  <p>Hence, a kind of "DataFrame within a DataFrame". Is that possible? How can one achieve that?</p>
  
  <p>Data in df1 looks like this, columns [value, batchNumber, timestamp, otherID]:</p>
  
  <pre><code>[[3.06130831419325e-05 1552608005236178640 '2019-03-15T00:00:05.236178688Z' 1552608005236178640]
  [3.1214206203101214e-05 1552608010657198640 '2019-03-15T00:00:10.657198592Z' 1552608010657198640]
  [2.9220824990100192e-05 1552608016078218640 '2019-03-15T00:00:16.078218752Z' 1552608016078218640]
  [3.1036932744355974e-05 1552608021499238640 '2019-03-15T00:00:21.499238656Z' 1552608021499238640]
  [2.9085449547509336e-05 1552608026920258640 '2019-03-15T00:00:26.92025856Z' 1552608026920258640]
          ...
  </code></pre>
  
  <p>Data in df2 looks like follows, columns [value, batchNumber, timestamp, otherID]:</p>
  
  <pre><code>[[512.5499877929688 1552608005236178640 '2019-03-15T00:00:05.236178688Z' 1552608005236178640]
   [512.7000122070312 1552608005236178640 '2019-03-15T00:00:05.236180736Z' 1552608005236178640]
   [513.0999755859375 1552608005236178640 '2019-03-15T00:00:05.236182528Z' 1552608005236178640]
   [513.0 1552608005236178640 '2019-03-15T00:00:05.236184576Z' 1552608005236178640]
   [513.5 1552608005236178640 '2019-03-15T00:00:05.236186624Z' 1552608005236178640]
   [512.8499755859375 1552608005236178640 '2019-03-15T00:00:05.236188672Z' 1552608005236178640]
   [513.3499755859375 1552608005236178640 '2019-03-15T00:00:05.23619072Z' 1552608005236178640]
   [512.9500122070312 1552608005236178640 '2019-03-15T00:00:05.236192768Z' 1552608005236178640]
   [513.2000122070312 1552608005236178640 '2019-03-15T00:00:05.23619456Z' 1552608005236178640]
   [513.2000122070312 1552608005236178640 '2019-03-15T00:00:05.236196608Z' 1552608005236178640]
   [512.8499755859375 1552608005236178640 '2019-03-15T00:00:05.23619...
  </code></pre>
  
  <p>As one can see, there are on batchNumber value in df1 and the same batchNumber many times in df2, creating a 1:n relation between the lines of df1 and df2.</p>
  
  <p>I would like to have all lines of df2 matching the batchID of df1 as a subtable/list/DataFrame in a new cell added to df1, symbolically speaking:</p>
  
  <pre><code>df_new.row = df1.row + df2.subset(batchNumber(df2) == batchNumber(df1))
  </code></pre>