title: Faster copying of pandas data with some conditions
body: <p>I have a dataframe(<strong>df_main</strong>) into which I want to copy the data based on finding the necessary columns from another dataframe(<strong>df_data</strong>).</p>
  
  <pre><code>df_data
     name  Index     par_1   par_2 ... par_n
  0    A1      1        a0      b0
  1    A1      2        a1
  2    A1      3        a2
  3    A1      4        a3 
  4    A2      2        a4
  ...    
  
  df_main
     name Index_0  Index_1    
  0    A1       1        2
  1    A1       1        3
  2    A1       1        4
  3    A1       2        3 
  4    A1       2        4
  5    A1       3        4
  ...
  
  </code></pre>
  
  <p>I want to copy the parameter columns from <strong>df_data</strong> into <strong>df_main</strong> with the condition that all the parameters with same name and index in df_data row are copied to the df_main.
  I have made the following implementation using for loops which is practically too slow to be used:</p>
  
  <pre class="lang-py prettyprint-override"><code>def data_copy(df, df_data, indice):
      '''indice: whether Index_0 or Index_1 is being checked'''
      names = df['name'].unique()
      # We get all different names in the dataset to loop over
      for name in tqdm.tqdm(names):
          # Get unique index for a specific name
          indexes = df[df['name']== name][indice].unique()
          # Looping over all indexes
          for index in indexes:
              # From df_data, get the data of all cols of specific name and data
              data = df_data[(df_data['Index']==index) &amp; (df_data['name'] == name)]
  
              # columns: Only the cols of structure's data
              req_data = data[columns]
  
              for col in columns:
                  # For each col (e.g. g1, g2, etc), get the val of a specific index
                  val = df_struc.loc[(df_data['Index']==index) &amp; (df_data['name'] == name), col]
                  df.loc[(df[indice] == index) &amp; (df['name']== name), col] = val[val.index.item()]
      return df
  
  df_main = data_copy(df_main, df_data, 'Index_0') 
  </code></pre>
  
  <p>This gives me what I required as:</p>
  
  <pre><code>df_main
     name Index_0  Index_1   par_1    par_2 ...
  0    A1       1        2      a0
  1    A1       1        3      a0    
  2    A1       1        4      a0
  3    A1       2        3      a1
  4    A1       2        4      a1
  5    A1       3        4      a2
  </code></pre>
  
  <p>However, running it on a really big data requires a lot of time. What's the best way of avoiding the for loops for a faster implementation?</p>