Menu

Python: Stack Three Monthly Exports Into One Quarter With pandas (Label, concat, groupby, No Copy-Paste)
📰

Python: Stack Three Monthly Exports Into One Quarter With pandas (Label, concat, groupby, No Copy-Paste)

DEV Community: beginners·Robert Breen·1 day ago
#PbeJbTAq
#devtobeginners#devto#dev#month#customer
Reading 0:00
15s threshold

Most small-business software exports one file per month. Sales, invoices, time sheets: July is one CSV, August is another.

Then the quarterly review comes around, and someone opens all three, pastes them under each other, deletes the header row that got pasted in twice, and hopes nothing was skipped. If the totals look off, they start again.

pandas does that stacking in one line, with no repeated headers and nothing skipped. Here's the version from my free lesson. It runs in Google Colab with a free Google account, nothing to install.

Three small monthly tables

Lakeside Office Supply is a made-up shop with two orders a month. In a new Colab notebook, run import pandas as pd , then in the next cell:

july = pd . DataFrame ({ ' customer ' : [ ' Maple Dental ' , ' Cobalt Legal ' ], ' amount ' : [ 1250 , 860 ]}) august = pd . DataFrame ({ ' customer ' : [ ' Cobalt Legal ' , ' Harbor Accounting ' ], ' amount ' : [ 2310 , 640 ]}) september = pd .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.