Hi,
I am reading an XML file and want to append the data to the list. I want to append corresponding elements in their respective columns, for example, I want to append the author name in author columns, and price in price columns, etc. Here I can only append one element. But how to append multiple elements in respective columns. or How to save into a data frame.
I am reading an XML file and want to append the data to the list. I want to append corresponding elements in their respective columns, for example, I want to append the author name in author columns, and price in price columns, etc. Here I can only append one element. But how to append multiple elements in respective columns. or How to save into a data frame.
import xml.etree.ElementTree as ET mytree = ET.parse(r'D:\testxml2.xml') myroot = mytree.getroot() print(myroot) data = [] for x in myroot.findall('book'): if(x.find('author'))==None: print("NA") data.append("NA") else: print(x.find('author').text) data.append(x.find('author').text)