0
0
Pandasdata~15 mins

Memory usage analysis in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Memory usage analysis
📖 Scenario: You work as a data analyst. You have a small dataset about sales of different products. You want to understand how much memory this data uses in your computer. This helps you learn about data size and efficiency.
🎯 Goal: You will create a pandas DataFrame with sales data, then check its memory usage. Finally, you will print the memory usage in bytes.
📋 What You'll Learn
Create a pandas DataFrame with exact data given
Use pandas method to find memory usage of the DataFrame
Print the memory usage value
💡 Why This Matters
🌍 Real World
Data scientists often check memory usage to optimize data storage and processing speed, especially with large datasets.
💼 Career
Understanding memory usage helps data analysts and scientists write efficient code and manage resources well in real projects.
Progress0 / 4 steps
1
Create the sales DataFrame
Import pandas as pd. Create a DataFrame called sales with these exact columns and values: 'Product' with ['Pen', 'Notebook', 'Eraser'], 'Units' with [10, 5, 8], and 'Price' with [1.5, 3.0, 0.5].
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of data.

2
Set up memory usage variable
Create a variable called mem_usage and set it to the memory usage of the sales DataFrame by using the memory_usage() method with deep=True and then summing the result.
Pandas
Need a hint?

Use sales.memory_usage(deep=True) to get memory per column, then .sum() to add them.

3
Calculate total memory usage
Use the variable mem_usage to hold the total memory usage in bytes of the sales DataFrame by summing the memory usage of all columns with deep=True.
Pandas
Need a hint?

This step repeats the calculation to reinforce the concept. Make sure you use deep=True and .sum().

4
Print the memory usage
Print the value of mem_usage to show the total memory usage in bytes of the sales DataFrame.
Pandas
Need a hint?

Use print(mem_usage) to display the memory usage.