Complete the code to create an ordered categorical type with levels 'low', 'medium', 'high'.
import pandas as pd levels = ['low', 'medium', 'high'] cat_type = pd.CategoricalDtype(categories=levels, ordered=[1])
Setting ordered=True creates an ordered categorical type.
Complete the code to convert a column 'priority' in DataFrame df to the ordered categorical type cat_type.
df['priority'] = df['priority'].astype([1])
Use astype(cat_type) to convert the column to the ordered categorical type.
Fix the error in the code to compare if 'priority' is greater than 'medium'.
result = df['priority'] [1] 'medium'
Ordered categorical types support comparison operators like >.
Fill both blanks to create a dictionary of counts for categories greater than 'low'.
counts = {cat: sum(df['priority'] [1] cat) for cat in cat_type.categories if cat [2] 'low'}We count how many rows have priority greater than each category, and only for categories greater than 'low'.
Fill both blanks to create a filtered DataFrame with priority between 'medium' and 'high' inclusive.
filtered = df[(df['priority'] [1]= 'medium') & (df['priority'] [2]= 'high')]
Use >= for the lower bound and <= for the upper bound.