Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a large CSV file efficiently using NumPy.
NumPy
import numpy as np large_data = np.genfromtxt('data.csv', delimiter=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong delimiter like semicolon or tab.
Forgetting to specify the delimiter.
✗ Incorrect
The delimiter for CSV files is a comma, so we use ',' to correctly parse the file.
2fill in blank
mediumComplete the code to load only the first 1000 rows from a large file using NumPy.
NumPy
import numpy as np subset_data = np.genfromtxt('data.csv', delimiter=',', max_rows=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using max_rows larger than the file size.
Not using max_rows and loading the entire file.
✗ Incorrect
Setting max_rows=1000 loads only the first 1000 rows, which helps handle large files efficiently.
3fill in blank
hardFix the error in the code to load a large binary file efficiently with NumPy.
NumPy
import numpy as np large_array = np.fromfile('data.bin', dtype=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Python types like 'int' or 'list' instead of NumPy dtypes.
Using 'string' which is not valid for binary numeric data.
✗ Incorrect
The dtype must be a valid NumPy data type like 'float64' to correctly read binary data.
4fill in blank
hardFill both blanks to create a memory-mapped array for efficient large file access.
NumPy
import numpy as np memmap_array = np.memmap('large_data.dat', dtype=[1], mode=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mode='w+' which overwrites the file.
Using an incorrect dtype that doesn't match the file data.
✗ Incorrect
Using dtype='float32' and mode='r+' creates a memory-mapped array for reading and writing efficiently.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
NumPy
words = ['data', 'science', 'ai', 'ml'] lengths = { [1] : [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not filtering words by length.
✗ Incorrect
The comprehension uses 'word' as the variable, maps word to its length, and filters words longer than 3 characters.