Q:

change value of tag respecting conditions

I want to read a csv file.
The first column refers the tag source, the second column refers to the value source, the third column refers to the target value to change . The last column refers to the tag name changed. 
How can I do it dynamically please?
 Types1, Init, INITIAL, Type1

 Types1, inits, INITIAL, Type1

 Types2, ANNULE, delayed, Type2

 Types3, Topp, high, Type3

 Types3, best, TOP, Type3

Input sample
<data>
  <db1>
    <Types1> Init </Types1>
    <Types1> inits </Types1>
    <Types3> best </Types3>
  </db1>
  <db1>
    <Types2> ANNULE </Types2>
    <Types3> Topp </Types3>
    <Types3> best </Types3>
  </db1>   
<data>

Expected Output
<data>
  <db1>
    <Type1> INITIAL </Type1>
    <Type1> INITIAL </Type1>
    <Type3> TOP </Type3>
  </db1>
  <db1>
    <Type2> delayed </Type2>
    <Type3> high </Type3>
    <Type3> TOP </Type3>
  </db1>   

A:

For csv data like below:

You need to use pandas to manage csv and ElementTree to manage xml file.
import xml.etree.ElementTree
import pandas as pd

df = pd.read_csv('data.csv')
root = xml.etree.ElementTree.parse('data.xml')

for tag in df['tag'].unique():
    for item in root.iter(tag):
        text = item.text.strip()
        data_row = df[(df['tag']==tag) & (df['old']==text)]
        item.text = data_row['new'].values[0]

root.write('file_new.xml')

Output:
<data>
  <db1>
    <Types1>INITIAL</Types1>
    <Types1>INITIAL</Types1>
    <Types3> best </Types3>
  </db1>
  <db1>
    <Types2>delayed</Types2>
    <Types3> Topp </Types3>
    <Types3> best </Types3>
  </db1>   
</data>

