text: user12707: I have into a dictionary some sequences. I would like to replace the sequences name for new names contained into a dataframe.
  #my sequences into a dictionary
  sequence = {"seq01": "agatcatggctaactatgcacgtgca",             
             "seq02": "atatcatggctaactatgcacgtgca",
             "seq03": "tgatcatggctaactatgcacgtgca"}
  
  #my data frame containing old names and new names
  data = {"old_name": ["seq01", "seq02","seq03"], "new_name": ["sample1", "sample2", "sample3"]}
  data = pd.DataFrame(data)
  print(data)
  
  I tried to replace the old names with a for loop, but it was imposible to do it.
  Thank you
  
  user3541: I am pretty sure there would be more elegant, in-place solutions but here is a quick solution to your problem. Should be OK if your sequence dictionary is not way too large.
  seq_names = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
  renamed_sequence = {}
  for i in seq_names:
      renamed_sequence[i[1]] = sequence[i[0]]
  renamed_sequence
  
  EDIT: The section below is not quite accurate, please see the comments below.
  And regarding your comment:
  
  I tried to replace the old names with a for loop, but it was imposible
  to do it.
  
  You are not supposed to loop over and at the same time modify an element at the same time anyway (there might be side effects that you would not think of), hence a brand new dictionary in my code.
  
original_text: 12707: <p>I have into a dictionary some sequences. I would like to replace the sequences name for new names contained into a dataframe.</p>
  <pre><code>#my sequences into a dictionary
  sequence = {&quot;seq01&quot;: &quot;agatcatggctaactatgcacgtgca&quot;,             
             &quot;seq02&quot;: &quot;atatcatggctaactatgcacgtgca&quot;,
             &quot;seq03&quot;: &quot;tgatcatggctaactatgcacgtgca&quot;}
  
  #my data frame containing old names and new names
  data = {&quot;old_name&quot;: [&quot;seq01&quot;, &quot;seq02&quot;,&quot;seq03&quot;], &quot;new_name&quot;: [&quot;sample1&quot;, &quot;sample2&quot;, &quot;sample3&quot;]}
  data = pd.DataFrame(data)
  print(data)
  </code></pre>
  <p>I tried to replace the old names with a for loop, but it was imposible to do it.</p>
  <p>Thank you</p>
   3541: <p>I am pretty sure there would be more elegant, in-place solutions but here is a quick solution to your problem. Should be OK if your <code>sequence</code> dictionary is not way too large.</p>
  <pre><code>seq_names = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
  renamed_sequence = {}
  for i in seq_names:
      renamed_sequence[i[1]] = sequence[i[0]]
  renamed_sequence
  </code></pre>
  <p>EDIT: The section below is not quite accurate, please see the comments below.</p>
  <p>And regarding your comment:</p>
  <blockquote>
  <p>I tried to replace the old names with a for loop, but it was imposible
  to do it.</p>
  </blockquote>
  <p>You are not supposed to loop over and at the same time modify an element at the same time anyway (there might be side effects that you would not think of), hence a brand new dictionary in my code.</p>
  