Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read a CSV file with UTF-8 encoding.
Pandas
import pandas as pd df = pd.read_csv('data.csv', encoding=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong encoding like 'ascii' which may cause errors.
Not specifying encoding when the file is not UTF-8.
✗ Incorrect
The UTF-8 encoding is the most common encoding for text files and is used here to correctly read the CSV file.
2fill in blank
mediumComplete the code to read a CSV file with Latin-1 encoding.
Pandas
import pandas as pd df = pd.read_csv('data_latin1.csv', encoding=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'utf-8' when the file is actually Latin-1 encoded.
Not specifying encoding and getting decoding errors.
✗ Incorrect
Latin-1 encoding is often used for Western European languages and can help avoid errors when UTF-8 fails.
3fill in blank
hardFix the error in the code to read a CSV file with UTF-16 encoding.
Pandas
import pandas as pd df = pd.read_csv('data_utf16.csv', encoding=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'utf-8' for a UTF-16 encoded file causes errors.
Not specifying encoding and getting decoding errors.
✗ Incorrect
UTF-16 encoding is used for some files and must be specified correctly to avoid errors.
4fill in blank
hardFill both blanks to read a CSV file with encoding and handle errors by ignoring bad characters.
Pandas
import pandas as pd df = pd.read_csv('data.csv', encoding=[1], errors=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using errors='strict' which raises errors on bad characters.
Using wrong encoding causing decoding errors.
✗ Incorrect
Using 'utf-8' encoding and setting errors='ignore' skips bad characters without stopping the program.
5fill in blank
hardFill all three blanks to read a CSV file with encoding, handle errors by replacing bad characters, and display the first 5 rows.
Pandas
import pandas as pd df = pd.read_csv('data.csv', encoding=[1], errors=[2]) print(df.[3]())
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using errors='ignore' when replacement is needed.
Not calling head() to preview data.
Using wrong encoding causing errors.
✗ Incorrect
Using 'utf-8' encoding with errors='replace' replaces bad characters, and df.head() shows the first 5 rows.