Project 8: Guest Ratings Converter
Data Engineer
Builds on these lessons
Current Task
Objective
Every array has a single dtype shared by all its elements. .astype() converts an array to a new dtype, like turning string ratings into floats.
Task: print an integer array's dtype, then convert a string array of ratings to floats and print its new dtype.
index.py
import numpy as np
guests = np.array([1, 2, 3])
print(guests.dtype)
ratings = np.array(['4.5', '3.8', '5.0'])
float_ratings = ratings.astype('f')
print(float_ratings.dtype)
* Hint: Correct characters turn green, incorrect ones turn red.
Live Preview
🖼️
Verify your code to see the preview