Complete the code to convert a Pandas Series to a NumPy array.
import pandas as pd 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 numpy as np import pandas as pd arr = np.array([[1, 2], [3, 4]]) df = pd.DataFrame([1])
You can pass a NumPy array directly to pd.DataFrame() to create a DataFrame.
Fix the error in the code to get the mean of a NumPy array column in a DataFrame.
import numpy as np import pandas as pd data = {'A': np.array([1, 2, 3]), 'B': [4, 5, 6]} df = pd.DataFrame(data) mean_col = df['A'].[1]()
The correct method to get the mean of a Series is mean(), but in the blank you only put the method name without parentheses because parentheses are already in the code.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if length is greater than 3.
words = ['data', 'science', 'is', 'fun'] lengths = { [1] : [2] for word in words if len(word) > 3 }
The dictionary comprehension maps each word to its length using len(word).
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their values only if value is greater than 0.
data = {'a': 1, 'b': -1, 'c': 3}
result = { [1] : [2] for k, v in data.items() if v [3] 0 }The comprehension maps the uppercase key k.upper() to the value v only if v > 0.