0
0
Pandasdata~15 mins

dtypes and data type checking in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding dtypes and Data Type Checking in pandas
📖 Scenario: You work in a small store and keep track of daily sales data. You want to make sure the data you have is in the right format before doing any analysis.
🎯 Goal: Learn how to create a pandas DataFrame, check the data types of each column, and understand how pandas stores data types.
📋 What You'll Learn
Create a pandas DataFrame with specific sales data
Check the data types of the DataFrame columns using dtypes
Use type() to check the data type of a specific column
Print the data types to see the results
💡 Why This Matters
🌍 Real World
Checking data types is important before analyzing data to avoid errors and understand the kind of data you have.
💼 Career
Data scientists and analysts often check and convert data types to prepare data for analysis and modeling.
Progress0 / 4 steps
1
Create the sales DataFrame
Import pandas as pd and create a DataFrame called sales with these exact columns and values: 'day': ['Monday', 'Tuesday', 'Wednesday'], 'items_sold': [10, 15, 7], 'revenue': [100.5, 150.75, 70.0]
Pandas
Need a hint?

Use pd.DataFrame and pass a dictionary with the exact keys and values.

2
Check the data types of all columns
Create a variable called data_types and set it to sales.dtypes to get the data types of each column.
Pandas
Need a hint?

Use the dtypes attribute of the DataFrame to see each column's data type.

3
Check the data type of the 'items_sold' column
Create a variable called items_sold_type and set it to the result of type(sales['items_sold']) to check the data type of the 'items_sold' column.
Pandas
Need a hint?

Use the type() function on the column sales['items_sold'].

4
Print the data types
Print the variables data_types and items_sold_type to see the data types of the DataFrame columns and the 'items_sold' column type.
Pandas
Need a hint?

Use two print() statements to show the variables.