Spreadsheets often arrive wide: one row per region and one column per month. pandas works best long: one row per region and month, with the month as a value. melt turns wide into long:
wide.melt(id_vars="region", var_name="month", value_name="target")
id_vars are the columns to keep as they're (they repeat on every new row).
- Every other column is "melted": its name goes into
var_name and its value into value_name. value_vars=[...] melts only some of them.
In long form, totals and filters become ordinary groupby and mask operations. One trap: month names are text, so sorting by them gives Apr, Feb, Jan... Map them to numbers (or use an ordered category) when the calendar order matters.