Complete the code to create a NumPy array from a pandas Series.
import pandas as pd import numpy as np s = pd.Series([1, 2, 3, 4]) arr = s.[1]()
The to_numpy() method converts a pandas Series to a NumPy array.
Complete the code to create a pandas DataFrame from a NumPy array.
import pandas as pd import numpy as np arr = np.array([[1, 2], [3, 4]]) df = pd.[1](arr, columns=['A', 'B'])
The DataFrame constructor creates a DataFrame from a NumPy array.
Fix the error in the code to convert a pandas DataFrame column to a NumPy array.
import pandas as pd import numpy as np df = pd.DataFrame({'col': [10, 20, 30]}) arr = df['col'].[1]
The to_numpy() method converts the DataFrame column to a NumPy array. values is an attribute, not a method.
Fill both blanks to create a dictionary comprehension that maps each word to its length if the length is greater than 3.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension uses len(word) as the value and filters words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 3.
words = ['apple', 'bat', 'carrot', 'dog'] result = { [1]: [2] for word in words if [3] }
word.lower() instead of uppercase.word instead of len(word) for the value.The dictionary comprehension maps the uppercase version of each word to its length, filtering words longer than 3 characters.