Exercise: Data Typing and Structuring
Practice converting the data types and structuring them with examples.
Data typing
Suppose we extracted a dataset that includes a field called Price
that represents the price of a product in dollars. However, upon further inspection, we noticed that the column’s data type is a string instead of a float. Furthermore, the prices are formatted with a dollar sign and comma, such as '$1,000.00'
.
We know the data should eventually be loaded into a database table with a column data type of float. Our task is to remove the dollar sign and commas from the Price
column and then convert the data type to float
.
Let’s look at the Price
column using the head()
method, which prints the first five values in the column. It also prints the column’s data type, which is Object. The Object data type is used for strings in pandas.
Get hands-on with 1400+ tech skills courses.