title: Add/Update/Merge original DataFrame into a grouped DataFrame
body: <p><strong>How can I merge, update, join, concat, or filter the original DF correctly so that I can have the complete 78 columns?</strong></p>
  <p>I have a DataFrame with 22 rows and 78 columns. An internet-friendly version of the file can be found <a href="https://www.dropbox.com/s/x0w628bzi9gegr8/original_df.csv?dl=0" rel="nofollow noreferrer">here</a>. This a sample:</p>
  <pre><code>item_no     code            group   gross_weight    net_weight  value   ... ... +70 columns more
  1           7417.85.24.25   0       18              17          13018.74
  2           1414.19.00.62   1       35              33          0.11
  3           7815.80.99.96   0       49              48          1.86
  4           1414.19.00.62   1       30              27          2.7
  5           5867.21.36.92   1       31              24          94
  6           9227.71.84.12   1       24              17          56.4
  7           1414.19.00.62   0       42              35          0.56
  8           4465.58.84.31   0       50              42          0.94
  9           1596.09.32.64   1       20              13          0.75
  10          2194.64.27.41   1       38              33          1.13
  11          1596.09.32.64   1       53              46          1.9
  12          1596.09.32.64   1       18              15          10.44
  13          1596.09.32.64   1       35              33          15.36
  14          4835.09.81.44   1       55              47          10.44
  15          5698.44.72.13   1       51              49          15.36
  16          5698.44.72.13   1       49              45          2.15
  17          5698.44.72.13   0       41              33          16
  18          3815.79.80.69   1       25              21          4
  19          3815.79.80.69   1       35              30          2.4
  20          4853.40.53.94   1       53              46          3.12
  21          4853.40.53.94   1       50              47          3.98
  22          4853.40.53.94   1       16              13          6.53
  </code></pre>
  <p>The column group gives me the instruction that I should group all similar values in the code column and add the values in the columns: 'gross_weight', 'net_weight', 'value', and 'item_quantity'. Additionally, I have to modify 2 additional columns as shown below:</p>
  <pre><code>#Group DF
  grouped_df = df.groupby(['group', 'code'], as_index=False).agg({'item_quantity':'sum', 'gross_weight':'sum','net_weight':'sum', 'value':'sum'}).copy()
  
  #Total items should be equal to the length of the DF
  grouped_df['total_items'] = len(grouped_df)
  
  #Item No.
  grouped_df['item_no'] = [x+1 for x in range(len(grouped_df))]
  </code></pre>
  <p>This is the result:</p>
  <pre><code>    group   code            item_quantity   gross_weight    net_weight  value       total_items     item_no
  0   0       1414.19.00.62   75.0            42              35          0.56        14              1
  1   0       4465.58.84.31   125.0           50              42          0.94        14              2
  2   0       5698.44.72.13   200.0           41              33          16.0        14              3
  3   0       7417.85.24.25   1940.2          18              17          13018.74    14              4
  4   0       7815.80.99.96   200.0           49              48          1.86        14              5
  5   1       1414.19.00.62   275.0           65              60          2.81        14              6
  6   1       1596.09.32.64   515.0           126             107         28.45       14              7
  7   1       2194.64.27.41   151.0           38              33          1.13        14              8
  8   1       3815.79.80.69   400.0           60              51          6.4 18      14              9
  9   1       4835.09.81.44   87.0            55              47          10.44       14              10
  10  1       4853.40.53.94   406.0           119             106         13.63       14              11
  11  1       5698.44.72.13   328.0           100             94          17.51       14              12
  12  1       5867.21.36.92   1000.0          31              24          94.0        14              13
  13  1       9227.71.84.12   600.0           24              17          56.4        14              14
  </code></pre>
  <p>All of the columns in the grouped DF exist in the original DF but some have different values.</p>
  <p><strong>How can I merge, update, join, concat, or filter the original DF correctly so that I can have the complete 78 columns?</strong></p>
  <ul>
  <li>The objective DataFrame is the grouped DF.</li>
  <li>The columns in the original DF that already exists in the Grouped DF should be omitted.</li>
  <li>I should be able to take the first value of the columns in the original DF that aren't in the Grouped DF.</li>
  <li>The column code does not have unique values.</li>
  <li>The column part_number in the complete file does not have unique values.</li>
  </ul>
  <p>I tried:</p>
  <ul>
  <li>pd.Merge(how='left') after creating a unique ID; it duplicates existing columns instead of updating values or overwriting.</li>
  <li>join, concat, update: does not yield the expected results.</li>
  <li><code>.agg({lambda x: x.iloc[0]})</code> adds all the columns but I don't know how to add it to the current <code>.agg({'item_quantity':'sum', 'gross_weight':'sum','net_weight':'sum', 'value':'sum'})</code></li>
  <li>I know that <code>.agg({'column_name':'first'])</code> returns the first value, but I don't know how to make it work for over 70 columns automatically.</li>
  </ul>