Get startedGet started for free

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

View Course

Exercise instructions

  • Import titanic.csv using the function np.recfromcsv() and assign it to the variable, d. You'll only need to pass file to it because it has the defaults delimiter=',' and names=True, in addition to dtype=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])
Edit and Run Code