I have a xml which i want to convert into csv but i am getting error.
In my xml file i wish to write only selected columns into csv.
import xml.etree.ElementTree as ET
import pandas as pd
root = ET.parse('D:\\Task\\09_ActionRecorder_0.XML').getroot()
tags =[]
for elem in root:
for child in elem:
try:
tag = {}
tag["TL"] = child.attrib['TL']
tag["CN"] = child.attrib['CN']
tag["DT"] = child.attrib['DT']
tag["AN"] = child.attrib['AN']
tags.append(tag)
except KeyError:
tags.append(tag)
print(tags)
df_users = pd.DataFrame(tags)
#df_users.head(20)
column_name_update = df_users.rename(columns = {"TL": "Title",
"CN":"Control Name",
"DT": "Date Time",
"AN": "Application Name"})
#new_data.head(20)
column_name_update.to_csv("D:\\Tasks\\Sample.csv",index=False, columns=["Title", 'Control Name', 'Date Time', 'Application Name'])
From the given xml file i wish to write only limited no of columns(as shown in code).But whenever i execute above code i am getting key error and in csv file only one column is being getting written.Kindly help if any one know how to do so.