Python Forum
How to append elemnent in columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to append elemnent in columns
#1
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.

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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,523 Apr-22-2020, 01:01 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020