title: How to update and add attributes in a XML file by using python pandas data frame
body: <p>I am new to the XML, Is there any efficient way to match text using pandas data frame and update XML file ?</p>
  <p>This is a small part of my large XML file which still follows the appropriate format.</p>
  <p><strong>XML file</strong> (input.xml):</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;brand by=&quot;hhdhdh&quot; date=&quot;2014/01/01&quot; name=&quot;OOP-112200&quot; Insti=&quot;TGA&quot;&gt;
     &lt;design name=&quot;OOP-112200&quot; own=&quot;TGA&quot; descri=&quot;&quot; sound_db=&quot;JJKO&quot;&gt;
        &lt;sec name=&quot;abcd&quot; sound_freq=&quot;abcd&quot; c_ty=&quot;pv&quot;&gt;
           &lt;feature number=&quot;48&quot;&gt;
              &lt;tfgt v=&quot;0.1466469683747654&quot; y=&quot;0.0&quot; units=&quot;sec&quot; /&gt;
           &lt;/feature&gt;
           &lt;mwan sound_freq=&quot;abcd&quot; first_name=&quot;g7tty&quot; description=&quot;xyz&quot; /&gt;
        &lt;/sec&gt;
        &lt;sec name=&quot;M_20_K40745170&quot; sound_freq=&quot;mhr17:7907527-7907589&quot; tension=&quot;SGCGSCGSCGSCGSC&quot; s_c=&quot;0&quot;&gt;
           &lt;feature number=&quot;5748&quot;&gt;
              &lt;tfgt v=&quot;0.1466469683747654&quot; y=&quot;0.0&quot; units=&quot;sec&quot; /&gt;
           &lt;/feature&gt;
           &lt;mwan sound_freq=&quot;mhr17:7907527-7907589&quot; first_name=&quot;g7tty&quot; description=&quot;xyz&quot;&gt;
          &lt;/mwan&gt;
        &lt;/sec&gt;
        &lt;sec name=&quot;M_20_K40745171&quot; sound_freq=&quot;mhr17:7907528-7907599&quot; tension=&quot;SGCGSCGSCGSHHGSC&quot; s_c=&quot;0&quot;&gt;
           &lt;feature number=&quot;5748&quot;&gt;
              &lt;tfgt v=&quot;0.1466469683747654&quot; y=&quot;0.0&quot; units=&quot;sec&quot; /&gt;
           &lt;/feature&gt;
           &lt;mwan sound_freq=&quot;mhr17:7907527-7907589&quot; first_name=&quot;gtftty&quot; description=&quot;xyz&quot;&gt;
              &lt;xyz abc=&quot;trt&quot; id=&quot;abc&quot; /&gt;
              &lt;per fre=&quot;acc&quot; value=&quot;abc&quot; /&gt;
              &lt;per fre=&quot;xyz&quot; value=&quot;abc&quot; /&gt;
              &lt;per fre=&quot;yy&quot; value=&quot;abc&quot; /&gt;
           &lt;/mwan&gt;
        &lt;/sec&gt;
        #file continue....
     &lt;/design&gt;
  &lt;/brand&gt;
  </code></pre>
  <p><strong>Data frame</strong> (to use as input):</p>
  <pre><code>                name       Volum_5mb      Volum_40mb     Volum_70mb
  1     M_20_K40745170         89.00           44.00         77.00
  2     M_20_K40745171         77.00           65.00         94.00
  </code></pre>
  <p>I would like to match elements from <code>name</code> column and if match then use rest of column to make new attribute as below. For example, if elements (<code>M_20_K40745170</code>) from <code>df['name']</code> is present/matched then update the corresponding node with following lines respectively in the output file.</p>
  <pre><code>&lt;per fre=&quot;Volum_5mb&quot; value=&quot;89.00&quot;/&gt;
  &lt;per fre=&quot;Volum_40mb&quot; value=&quot;44.00&quot;/&gt;
  &lt;per fre=&quot;Volum_70mb&quot; value=&quot;77.00&quot;/&gt;
  </code></pre>
  <p>and so on.</p>
  <p>I want the output file to looks like</p>
  <p><strong>Desired XML</strong> (output.xml):</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;brand by=&quot;hhdhdh&quot; date=&quot;2014/01/01&quot; name=&quot;OOP-112200&quot; Insti=&quot;TGA&quot;&gt;
     &lt;design name=&quot;OOP-112200&quot; own=&quot;TGA&quot; descri=&quot;&quot; sound_db=&quot;JJKO&quot;&gt;
        &lt;sec name=&quot;abcd&quot; sound_freq=&quot;abcd&quot; c_ty=&quot;pv&quot;&gt;
           &lt;feature number=&quot;48&quot;&gt;
              &lt;tfgt v=&quot;0.1466469683747654&quot; y=&quot;0.0&quot; units=&quot;sec&quot; /&gt;
           &lt;/feature&gt;
           &lt;mwan sound_freq=&quot;abcd&quot; first_name=&quot;g7tty&quot; description=&quot;xyz&quot; /&gt;
        &lt;/sec&gt;
        &lt;sec name=&quot;M_20_K40745170&quot; sound_freq=&quot;mhr17:7907527-7907589&quot; tension=&quot;SGCGSCGSCGSCGSC&quot; s_c=&quot;0&quot;&gt;
           &lt;feature number=&quot;5748&quot;&gt;
              &lt;tfgt v=&quot;0.1466469683747654&quot; y=&quot;0.0&quot; units=&quot;sec&quot; /&gt;
           &lt;/feature&gt;
           &lt;mwan sound_freq=&quot;mhr17:7907527-7907589&quot; first_name=&quot;g7tty&quot; description=&quot;xyz&quot;&gt;
              &lt;per fre=&quot;Volum_5mb&quot; value=&quot;89.00&quot; /&gt;
              #new attribute FYI
              &lt;per fre=&quot;Volum_40mb&quot; value=&quot;44.00&quot; /&gt;
              #new attribute FYI
              &lt;per fre=&quot;Volum_70mb&quot; value=&quot;77.00&quot; /&gt;
              #new attribute FYI
           &lt;/mwan&gt;
        &lt;/sec&gt;
        &lt;sec name=&quot;M_20_K40745171&quot; sound_freq=&quot;mhr17:7907528-7907599&quot; tension=&quot;SGCGSCGSCGSHHGSC&quot; s_c=&quot;0&quot;&gt;
           &lt;feature number=&quot;5748&quot;&gt;
              &lt;tfgt v=&quot;0.1466469683747654&quot; y=&quot;0.0&quot; units=&quot;sec&quot; /&gt;
           &lt;/feature&gt;
           &lt;mwan sound_freq=&quot;mhr17:7907527-7907589&quot; first_name=&quot;gtftty&quot; description=&quot;xyz&quot;&gt;
              &lt;xyz abc=&quot;trt&quot; id=&quot;abc&quot; /&gt;
              &lt;per fre=&quot;acc&quot; value=&quot;abc&quot; /&gt;
              &lt;per fre=&quot;xyz&quot; value=&quot;abc&quot; /&gt;
              &lt;per fre=&quot;yy&quot; value=&quot;abc&quot; /&gt;
              &lt;per fre=&quot;Volum_5mb&quot; value=&quot;77.00&quot; /&gt;
              #new attribute FYI
              &lt;per fre=&quot;Volum_40mb&quot; value=&quot;65.00&quot; /&gt;
              #new attribute FYI
              &lt;per fre=&quot;Volum_70mb&quot; value=&quot;94.00&quot; /&gt;
              #new attribute FYI
           &lt;/mwan&gt;
        &lt;/sec&gt;
        #file continue....
     &lt;/design&gt;
  &lt;/brand&gt;
  </code></pre>
  <p>I am trying etree.ElementTree module</p>
  <pre><code> import xml.etree.ElementTree as ET
  tree = ET.parse('input.xml')
  root = tree.getroot()
  for i in range(len(df)):
      for node in tree.findall(&quot;./design/sec&quot;):
          name = node.attrib.get('name')
          if  name == df.loc[i, 'name']:
              print(name)
  
  
  
  
  
          
  </code></pre>
  <p>I am new to this Python-XML coding. I dont have any idea how to add new attributes in a XML file by using pandas data frame.
  Please help.
  Thanks and Regards.</p>