Your channel_summary block is ten lines of logic you've already debugged. What happens when you need the same calculation for a different report next month?
I'd copy the block and rename the variables. Which I've definitely done in Excel — duplicate a sheet, rename it, pray nothing drifts.
Python has a better answer. A named function is a macro you wrote once and call forever. def summarize_channel(campaigns, channel="all"): — name it, document it in a docstring, give the channel argument a sensible default. Next month's report is the same single line. No copy, no drift, no diverging sheets.
And the Salesforce CSV exports that land on Monday — can Python read those directly instead of me opening them in Excel first?
That's exactly the second half of the week. A CSV export is a string with commas and newlines. csv.DictReader turns each row into a dict — field name to value, exactly like a Salesforce record. Pass the text in, get a list of campaign dicts out, hand it straight to channel_summary. By Friday, the Monday pivot table is a function call.
make_report_line: named, documented function with a rank paramsummarize_channel: default args + tuple return — portfolio or single channelparse_campaign_csv: split a CSV string into campaign dictsload_campaigns_from_csv: upgrade to csv.DictReader + io.StringIOcampaigns_to_json: serialise with json.dumpsGoal: reusable function chain that reads a CSV export, aggregates by channel, and outputs structured text — Monday pivot work in one pass.
7 lessons this week
Your channel_summary block is ten lines of logic you've already debugged. What happens when you need the same calculation for a different report next month?
I'd copy the block and rename the variables. Which I've definitely done in Excel — duplicate a sheet, rename it, pray nothing drifts.
Python has a better answer. A named function is a macro you wrote once and call forever. def summarize_channel(campaigns, channel="all"): — name it, document it in a docstring, give the channel argument a sensible default. Next month's report is the same single line. No copy, no drift, no diverging sheets.
And the Salesforce CSV exports that land on Monday — can Python read those directly instead of me opening them in Excel first?
That's exactly the second half of the week. A CSV export is a string with commas and newlines. csv.DictReader turns each row into a dict — field name to value, exactly like a Salesforce record. Pass the text in, get a list of campaign dicts out, hand it straight to channel_summary. By Friday, the Monday pivot table is a function call.
make_report_line: named, documented function with a rank paramsummarize_channel: default args + tuple return — portfolio or single channelparse_campaign_csv: split a CSV string into campaign dictsload_campaigns_from_csv: upgrade to csv.DictReader + io.StringIOcampaigns_to_json: serialise with json.dumpsGoal: reusable function chain that reads a CSV export, aggregates by channel, and outputs structured text — Monday pivot work in one pass.