title: How merge two rows in one row in pandas?
body: <p>I have this DataFrame:</p>
  <pre><code>    id   type    value
  0  104     0       7999
  1  105     1  196193579
  2  108     0     245744
  3  108     1   93310128
  </code></pre>
  <p>I need to merge rows that have the same <code>id</code> and keep the two values in the same row, the following example is what I require:</p>
  <pre><code>    id   type    value_0     value_1
  0  104     0       7999       0
  1  105     1        0      196193579
  2  108     0     245744    93310128
  </code></pre>
  <p>I have the following code, with which to group and change the values for each row</p>
  <pre><code> def concat_rows(self, rows ):
          row = rows.iloc[0]
  
          if len(rows) &gt; 1:
              row1 = rows.iloc[0]
              row2 = rows.iloc[1]
              row['value_1'] = row1['value'] if row1['type'] == 1 else row2['value']
              row['value_0'] = row1['value'] if row1['type'] == 0 else row2['value']
          else:
  
              row['value_1'] = row['value'] if row['type'] == 1 else 0
              row['value_0'] = row['value'] if row['type'] == 0 else 0
          return row
  
  df2 = df.groupby('id').apply(self.concat_rows).reset_index(drop=True)
  </code></pre>
  <p>But I get the following the following table with the modified numbers</p>
  <pre><code>    id  value    type  value_1  value_0
  0  104   7999     0        0     7999
  1  105     99     1       99      399
  2  108  10770     0    12118    10770
  </code></pre>
  <p>Data:</p>
  <pre><code>{'id': [104, 105, 108, 108],
   'type': [0, 1, 0, 1],
   'value': [7999, 196193579, 245744, 93310128]}
  </code></pre>