title: Pandas groupbyObject to DataFrame to merge
body: <p>I have two <code>DataFrame</code> they have the same index. </p>
  
  <p>Dataframe 1 let's call this 'click' Has multiple lines with the same value for each index. Something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/r7KJ5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r7KJ5.png" alt="enter image description here"></a></p>
  
  <p>DataFrame 2: Should has only one line for each index, let's call it 'train_data'. Something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/lVyzz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lVyzz.png" alt="enter image description here"></a></p>
  
  <p>I tryed to group by <code>DataFrame 1</code>and then add the values to my DataFrame 2 like this:</p>
  
  <pre><code>click_gb = click.groupby('COLUMN_WHAT_I_NEED')
  train_data['COLUMN_WHAT_I_NEED'] = click_gb['COLUMN_WHAT_I_NEED']
  </code></pre>
  
  <p>But, it's added to DataFrame 2 every rows that belongs to that index in DataFrame 1. Like this:</p>
  
  <p><a href="https://i.stack.imgur.com/WxS13.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WxS13.png" alt="enter image description here"></a> </p>
  
  <p>Help me please, how can I solve this.</p>
  
  <p>Sorry it wasn't clear: here comes a sample code:</p>
  
  <pre><code>import pandas as pd
  data1 = {
      'idx': [1,1,1,2,2,2],
      'what_i_need': ['Some_Value','Some_Value','Some_Value','Other_Value','Other_Value','Other_Value'],
      'other_column' : ['1','2','3','4','5','6']
  }
  data2 = {
      'idx': [1,2],
      'what_i_need': ['Here_I_should_add_the_value','Here_I_should_add_the_value']        
  }
  click_df = pd.DataFrame(data1)
  train_df = pd.DataFrame(data2)
  click_df = click_df.set_index('idx')
  train_df = train_df.set_index('idx')
  
  print('My dataframes after setting index:')
  print(click_df.head())
  print(train_df.head())
  
  click_df_gr = click_df.groupby('what_i_need')
  print('Group by object:')
  print(click_df_gr.head())
  
  train_df['what_i_need'] = click_df_gr['what_i_need']
  print('this is how final result looks like:')
  print(train_df.head())
  </code></pre>
  
  <p>this is the output:</p>
  
  <pre><code>My dataframes after setting index:
       what_i_need other_column
  idx                          
  1     Some_Value            1
  1     Some_Value            2
  1     Some_Value            3
  2    Other_Value            4
  2    Other_Value            5
                       what_i_need
  idx                             
  1    Here_I_should_add_the_value
  2    Here_I_should_add_the_value
  Group by object:
       what_i_need other_column
  idx                          
  1     Some_Value            1
  1     Some_Value            2
  1     Some_Value            3
  2    Other_Value            4
  2    Other_Value            5
  2    Other_Value            6
  this is how final result looks like:
                                             what_i_need
  idx                                                   
  1    (Other_Value, [Other_Value, Other_Value, Other...
  2    (Some_Value, [Some_Value, Some_Value, Some_Val...
  </code></pre>
  
  <p>Thank you!</p>