0
0
Pandasdata~10 mins

Memory usage analysis in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check the memory usage of a DataFrame.

Pandas
import pandas as pd

df = pd.DataFrame({'A': range(1000), 'B': range(1000, 2000)})
memory = df.[1]()
print(memory)
Drag options to blanks, or click blank then click option'
Ahead
Binfo
Cdescribe
Dmemory_usage
Attempts:
3 left
💡 Hint
Common Mistakes
Using df.info() which shows summary but not detailed memory usage.
Using df.describe() which shows statistics, not memory.
Using df.head() which shows data rows, not memory.
2fill in blank
medium

Complete the code to get the total memory usage of the DataFrame in bytes.

Pandas
import pandas as pd

df = pd.DataFrame({'A': range(500), 'B': range(500, 1000)})
total_mem = df.memory_usage([1]).sum()
print(total_mem)
Drag options to blanks, or click blank then click option'
Adeep=False
Bindex=True
Cdeep=True
Dindex=False
Attempts:
3 left
💡 Hint
Common Mistakes
Using index=False which excludes index memory but not detailed object memory.
Using deep=False which gives less accurate memory usage.
Using index=True which includes index but not deep memory.
3fill in blank
hard

Fix the error in the code to correctly print the memory usage of column 'A'.

Pandas
import pandas as pd

df = pd.DataFrame({'A': ['a', 'b', 'c'], 'B': [1, 2, 3]})
mem_col = df['A'].[1](deep=True)
print(mem_col)
Drag options to blanks, or click blank then click option'
Amemory
Bmemory_usage
Cmemory_use
Dmem_usage
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like memory or mem_usage.
Forgetting parentheses after method name.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Pandas
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Using less than '<' instead of greater than '>'.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values for words longer than 4 characters.

Pandas
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
result = [1]: [2] for w in words if len(w) [3] 4}
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Bw
C>
Dlen(w)
Attempts:
3 left
💡 Hint
Common Mistakes
Using length as value instead of the word.
Using less than '<' instead of greater than '>'.
Not converting keys to uppercase.