Complete the code to check the data type of the 'age' column in the DataFrame.
import pandas as pd data = {'name': ['Alice', 'Bob'], 'age': [25, 30]} df = pd.DataFrame(data) print(df['age'].[1])
The dtype attribute shows the data type of a single column in a DataFrame.
Complete the code to get the data types of all columns in the DataFrame.
import pandas as pd data = {'name': ['Alice', 'Bob'], 'age': [25, 30]} df = pd.DataFrame(data) print(df.[1])
The dtypes attribute returns a Series with the data types of all columns in the DataFrame.
Fix the error in the code to check if the 'score' column is of integer type.
import pandas as pd data = {'score': [88, 92, 79]} df = pd.DataFrame(data) print(df['score'].dtype == '[1]')
The dtype for integer columns in pandas is usually int64 on 64-bit systems.
Fill both blanks to create a dictionary comprehension that maps column names to their data types for columns with object type.
import pandas as pd data = {'name': ['Alice', 'Bob'], 'age': [25, 30], 'city': ['NY', 'LA']} df = pd.DataFrame(data) obj_cols = {col: df[col].[1] for col in df.columns if df[col].[2] == 'object'} print(obj_cols)
Accessing dtype.name gives the string name of the data type, which can be compared to 'object'.
Fill all three blanks to create a dictionary comprehension that maps column names to their data types for columns with numeric types.
import pandas as pd import numpy as np data = {'height': [5.5, 6.0], 'weight': [130, 150], 'name': ['Alice', 'Bob']} df = pd.DataFrame(data) numeric_cols = {col: df[col].[1] for col in df.columns if np.[2](df[col].dtype, np.number) and df[col].dtype != '[3]'} print(numeric_cols)
Use dtype to get the column's data type, np.issubdtype to check if it is numeric, and exclude 'object' dtype columns.