Openpivot tutorial

A few weeks ago I introduced openpivot on this blog. It is a powerful command line utility to build pivot tables. Assume you have the following simple file :

company Name;year;NbEmployee;profit;sector

What a complex data set ! Pivot tables are very powerful tools allowing you to make summary of your data from the point of view of your choice. Suppose you want to have per year and per sector, the average number of employees accross all entries. Here it is implicit that these entries will be only different companies as here there is 1 line per company/year. Note also that there is only 1 sector. So as there are 2 different years represented, and only 1 sector, you will get 2 statistics. Doing this with openpivot is simple. You only need to describe what pivot table you want in an xml file configuration and it will look like this:

<?xml version="1.0" encoding="UTF-8"?>
  <defaultaccumulation value="sum"/>
    <col id="NbEmployee" accumulation"average"/>
    <col id="profit"/> <!-- will use default accumulation -->
    <row id="year"/>
    <row id="sector"/>

This configuration is almost the pivot table we want for our example, except that there is an additional column we want to have a statistics for. Note that what we call row here the variable sequence from which you want to pivot. There are taken into account in the order specified. Just like in excel, changing the order of variables will offer a diferent view on your data. You are now ready to have your pivot table, all you need is to call openpivot to compute this from your sample data :

% openpivot -p configfile.xml -o outputfile.csv inputfile.csv

Et voila ! This will write your pivot table in the outputfile.csv.  Please drop me a line if you have problem to build openpivot. I have tested it on mac os 10.6 and various linux distribution, and it seemed to work

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: