An indicator variable is a derived column that marks whether a condition applies. It commonly contains 1 when a row matches and 0 otherwise, but it can also retain a relevant value—such as purchase price—and use 0 as the fallback. Summing the result isolates the count or value for the selected condition. section 4.4.2
Use indicators when raw categories cannot be treated as meaningful numeric scales. One-hot encoding creates one binary column per category, so each row records which category applies. For mutually exclusive categories, only one of those columns can be 1; this representation can serve as regression-model input. section 6.1.1
Monthly product metrics
For purchase events, create November and December count, revenue, and user columns. A November revenue indicator holds price for November purchases and 0 for all other rows; grouping by product and summing produces November revenue. Comparing the grouped monthly columns identifies products whose sales, revenue, or customer counts changed month to month. section 4.4.2
purchases
.assign(
november_count=np.where(purchases["event_time"].dt.month==11,
1, 0),
november_revenue=np.where(purchases["event_time"].dt.month==11,
purchases["price"], 0),
november_user_id=np.where(purchases["event_time"].dt.month==11,
purchases["user_id"], np.nan),
december_count=np.where(purchases["event_time"].dt.month==12,
1, 0),
december_revenue=np.where(purchases["event_time"].dt.month==12,
purchases["price"], 0),
december_user_id=np.where(purchases["event_time"].dt.month==12,
purchases["user_id"], np.nan))
This pandas transformation builds month-specific count, revenue, and user indicators before they are aggregated by product. section 4.4.2
Multiple-choice survey responses
A semicolon-delimited survey answer cannot be analyzed directly as one category when respondents can select several options. Split it into one indicator column per option, then take each column’s mean to estimate the percentage of respondents who selected that option. Combine the indicators with survey attributes to compare use cases by sentiment, trust, or job role. section 6.4.2 section 7.2.3



