0
0
Data Analysis Pythondata~30 mins

Memory usage analysis in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Memory usage analysis
📖 Scenario: You work in a small company that wants to understand how much memory different data structures use. This helps them choose the best way to store data efficiently.
🎯 Goal: You will create a dictionary with some data, set a variable to track memory size, calculate the memory used by each item, and finally print the total memory used.
📋 What You'll Learn
Create a dictionary with exact keys and values
Create a variable to hold total memory usage
Use a for loop to calculate memory usage of each dictionary item
Print the total memory usage
💡 Why This Matters
🌍 Real World
Understanding memory usage helps companies optimize their software to run faster and use less computer memory.
💼 Career
Data scientists and software engineers often analyze memory to improve program efficiency and reduce costs.
Progress0 / 4 steps
1
Create the data dictionary
Create a dictionary called data with these exact entries: 'item1': [1, 2, 3], 'item2': [4, 5], 'item3': [6].
Data Analysis Python
Need a hint?

Use curly braces {} to create a dictionary. Each key is a string and each value is a list of numbers.

2
Set up total memory variable
Create a variable called total_memory and set it to 0 to track the total memory used.
Data Analysis Python
Need a hint?

Just write total_memory = 0 to start counting memory.

3
Calculate memory usage for each item
Use a for loop with variables key and value to iterate over data.items(). Inside the loop, add the memory size of value to total_memory using sys.getsizeof(value). Import sys at the top.
Data Analysis Python
Need a hint?

Remember to import sys first. Then use for key, value in data.items(): to loop. Use sys.getsizeof(value) to get memory size.

4
Print the total memory used
Write a print statement to display the text Total memory used: followed by the value of total_memory.
Data Analysis Python
Need a hint?

Use print(f"Total memory used: {total_memory}") to show the result.