ComenzarEmpieza gratis

Skip bad data

In this exercise you'll use read_csv() parameters to handle files with bad data, like records with more values than columns. By default, trying to import such files triggers a specific error, pandas.errors.ParserError.

Some lines in the Vermont tax data here are corrupted. In order to load the good lines, we need to tell pandas to skip errors. We also want pandas to warn us when it skips a line so we know the scope of data issues.

pandas has been imported as pd. The exercise code will try to read the file. If there is a pandas.errors.ParserError, the code in the except block will run.

Este ejercicio forma parte del curso

Streamlined Data Ingestion with pandas

Ver curso

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

try:
  # Import the CSV without any keyword arguments
  data = ____
  
  # View first 5 records
  print(data.head())
  
except pd.errors.ParserError:
    print("Your data contained rows that could not be parsed.")
Editar y ejecutar código