Complete the code to check the memory usage of a DataFrame.
import pandas as pd df = pd.DataFrame({'A': range(1000), 'B': range(1000, 2000)}) memory = df.[1]() print(memory)
The memory_usage() method shows the memory used by each column in the DataFrame.
Complete the code to get the total memory usage of the DataFrame in bytes.
import pandas as pd df = pd.DataFrame({'A': range(500), 'B': range(500, 1000)}) total_mem = df.memory_usage([1]).sum() print(total_mem)
Using deep=True gives a more accurate memory usage including object types.
Fix the error in the code to correctly print the memory usage of column 'A'.
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)
The correct method to get memory usage of a Series is memory_usage().
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) for values and filters words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and values for words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] result = [1]: [2] for w in words if len(w) [3] 4} print(result)
The dictionary comprehension uses uppercase words as keys, original words as values, and filters words longer than 4 characters.