Embercode
✕
Data Formats and TextQuick quiz

Trees and cleaning

8 questions. Covers Data cleaning lab.

Questions 1 to 5 of 8

  1. 1. Put the four cleaning steps of the lab in the order the lab runs them.

    Use the arrows to put the steps in order.

    1. 1.Turn placeholder words and blank cells into one empty value
    2. 2.Skip any row whose name, city, signup and amount were already kept
    3. 3.Parse each signup date into the YYYY-MM-DD form
    4. 4.Read the file with the cp1252 encoding so the accented letters decode
  2. 2. Put these steps in the order the TreeBuilder class in the lesson handles the HTML <p>Free <strong>20</strong></p>.

    Use the arrows to put the steps in order.

    1. 1.The text Free is added as a string child of p
    2. 2.The end tag p moves the current element back up to the document
    3. 3.The start tag strong becomes a child of p, and strong becomes the current element
    4. 4.The start tag p becomes a child of the document, and p becomes the current element
    5. 5.The text 20 is added as a string child of strong
    6. 6.The end tag strong moves the current element back up to p
  3. 3. A row's signup cell holds only two spaces. This function is supposed to turn it into an empty value. What is its bug? ``python MISSING_WORDS = {"", "n/a", "-", "null"} def clean_text(value): if value.lower() in MISSING_WORDS: return "" return value ``
  4. 4. Running this code raises an error. What is the cause? ``python import xml.etree.ElementTree as ET root = ET.fromstring(text) # text holds library.xml from the lesson years = sum(b.findtext('year') for b in root) print(years) ``
  5. 5. Running this code raises an error. Why? ``python import csv with open('messy.csv', encoding='cp1252', newline='') as f: row = next(csv.DictReader(f)) print(row['Signup']) ``

3 question(s) left on this page.