Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- def parse_xml(series: pd.Series) -> list:
- """Input: xml, Returns list of dict"""
- xml = series.replace('">', '">\n')
- soup = BeautifulSoup(xml, features="xml")
- # returns list of all items within node
- values = [i.text.split("\n") for i in soup.find_all("node")] # replace "node" with relevent one
- stack = []
- for lst in values:
- items = {
- "item": lst[1], # change to keys and index to suit
- "length": lst[2],
- "width": lst[3],
- "height": lst[4],
- "quantity": lst[5],
- "height_band": lst[6],
- "eng_factor": lst[7],
- "m2_calc": lst[9]
- }
- stack.append(items)
- return stack
- # how to apply to series
- df["parsed_xml"] = df["parsed_xml"].apply(parse_xml)
Advertisement
Add Comment
Please, Sign In to add comment