Complete the code to create a structured array with fields 'name' and 'age'.
import numpy as np people = np.array([('Alice', 25), ('Bob', 30)], dtype=[1])
The dtype must define the field names and their data types. 'U10' means a Unicode string of length 10, and 'i4' means a 4-byte integer, suitable for age.
Complete the code to convert the structured array 'people' to a pandas DataFrame.
import pandas as pd df = pd.DataFrame([1])
You can pass the structured array directly to pd.DataFrame to create a DataFrame with columns matching the fields.
Fix the error in accessing the 'age' field from the structured array 'people'.
ages = people[1]To access a field in a structured array, use square brackets with the exact field name as a string.
Fill all four blanks to create a DataFrame from a dictionary comprehension that filters people older than 25.
df_filtered = pd.DataFrame([1]: [2] for [3] in people if [4] > 25)
The dictionary comprehension uses the person's name as keys and age as values for those older than 25.
Fill all three blanks to create a structured array from a list of tuples and then convert it to a DataFrame.
data = [('John', 28), ('Jane', 32)] arr = np.array(data, dtype=[[1], [2]]) df = pd.DataFrame([3])
The dtype is a list of tuples defining fields. Then the structured array is passed directly to pd.DataFrame.