Hierarchical consolidation in Python

Chris Angelico rosuav at gmail.com
Thu Sep 18 05:09:35 EDT 2014


On Thu, Sep 18, 2014 at 6:57 PM,  <ap501228 at gmail.com> wrote:
> Required to find:
>
> (1)Income, Expenses and Surplus consolidated for all units within a Department; and
> (2)Income, Expenses and Surplus consolidated for all departments within the company.
>
> I would welcome any help in expressing this problem directly in Python. Also, are there any Python modules or packages that enable problems of this type to be solved. Thanks in advance for any help.

This actually sounds more like a data-driven problem than a
code-driven one. If you store everything in a database table, with one
row for each business unit, and their departments, income, and
expenses, you could the do queries like this:

SELECT sum(income), sum(expenses), sum(income-expenses) as surplus
FROM units GROUP BY department

and that'd give you the per-department stats. Drop the GROUP BY to get
stats for the whole company.

If the job's simple enough, or if you already have the data in some
other format, you could do the same thing in Python code. It's
basically the same thing again - accumulate data by department, or
across the whole company.

ChrisA



More information about the Python-list mailing list