Posts Tagged ‘Unpivot’
Easily unpivot data using Python

Denormalized data in multiple columns
I was looking for an easy way to unpivot data, i.e. expand values from multiple columns in a single record into multiple records with the same values in a single column.

Normalized data in multiple records
Since the only tool available was SQL Server/SSIS, I wrote a short script in python (less than 50 lines of code) to easily unpivot CSV data.
Get the code here: http://pastie.textmate.org/713615
Options:
- -v Verbose
- -i Input file
- -o Output file
- -c Number of columns to be “frozen”, the default is one
Sample usage:
python unpivot.py -v -i GRP.csv -o GRPunpivot.csv -c 1