title: Collapse rows in pandas dataframe dataset
body: <p>I'm new to Pandas and am attempting to create a denormalized flat dataset and would like to gauge whether it’s even possible.  I’m starting with two dataframes, a parent and child, that can conceptually be joined on a single column (‘PID’).  </p>
  
  <p>Here is the parent dataframe:</p>
  
  <pre><code>parentData = [(1,’A’,100), (2,’B’,200)]
  parentCols = [‘PID’, ‘PATTR1’, ‘PATTR1’]
  parentDf = pd.DataFrame.from_records(parentData, columns=parentCols)
  
  Parent Dataframe
       PID  PATTR1  PATTR2
  0      1       A     100
  1      2       B     200
  </code></pre>
  
  <p>Here is the child dataframe:</p>
  
  <pre><code>childData = [(201,1,’AA’,2100), (202,2,’BB’,2200), (203,2,’CC’,2300)]
  childCols = [‘CID’, ‘PID’, ‘CATTR1’, ‘CATTR1’]
  childDf = pd.DataFrame.from_records(childData, columns=childCols)
  
  Child Dataframe
       CID  PID  PATTR1  PATTR2
  0    201    1      AA    2100
  1    202    2      BB    2200
  2    203    2      CC    2300
  </code></pre>
  
  <p>Here’s the merge of the parent and the child:</p>
  
  <pre><code>mergedDf = parentDf.merge(childDf, left_on=’PID’, right_on=’PID’, how=’outer’)
  
  Parent merged with Child dataframe
       PID  PATTR1  PATTR2  CID  CATTR1  CATTR2
  0      1       A     100  201      AA    2100
  1      2       B     200  202      BB    2200
  2      2       B     200  203      CC    2300
  </code></pre>
  
  <p>And here’s what the desired output is:</p>
  
  <pre><code>                          | ????                 | ????
       PID  PATTR1  PATTR2  | CID  CATTR1  CATTR2  | CID  CATTR1  CATTR2
  0      1       A     100  | 201      AA    2100  |
  1      2       B     200  | 202      BB    2200  | 203      CC    2300
  </code></pre>
  
  <p>After searching and reading through the merge, reshaping, etc. sections of the Pandas API docs, I wasn’t sure if the desired output is possible or not.</p>
  
  <p>Thanks in advance for any advice and/or help, it is greatly appreciated.</p>