Working with mixed datatypes (2)
You have just used np.genfromtxt() to import data containing
mixed datatypes. There is also another function np.recfromcsv() that behaves
similarly to np.genfromtxt(), except that its default
dtype is None. In this exercise, you'll practice using this to
achieve the same result.
This exercise is part of the course
Importing Data in Python
Exercise instructions
- Import
titanic.csvusing the functionnp.recfromcsv()and assign it to the variable,d. You'll only need to passfileto it because it has the defaultsdelimiter=','andnames=True, in addition todtype=None! - Run the remaining code to print the first three entries of the resulting array
d.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Assign the filename: file
file = 'titanic.csv'
# Import file using np.recfromcsv: d
# Print out first three entries of d
print(d[:3])