Jan 16, 2012 This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use.
![](/uploads/1/2/7/6/127643353/281515129.jpg)
Latest version
Released:
Create pivot tables and histograms from ORM querysets
Project description
This package provides utilities for turning Django Querysets intoPivot-Tables and Histogramsby letting your database do all the heavy lifting.
Examples
I am going to shamelessly lift examples from the wikipedia page referenced in the header.Here is part of the table of shirt sales:
![Pivot 1.0.2 download windows 10 Pivot 1.0.2 download windows 10](http://i737.photobucket.com/albums/xx11/lrzrage/BenQ%20tutorial/identifybenq.jpg)
Region | Gender | Style | Ship Date | Units | Price | Cost |
---|---|---|---|---|---|---|
East | Boy | Tee | 1/31/2005 | 12 | 11.04 | 10.42 |
East | Boy | Golf | 1/31/2005 | 12 | 13 | 12.6 |
East | Boy | Fancy | 1/31/2005 | 12 | 11.96 | 11.74 |
East | Girl | Tee | 1/31/2005 | 10 | 11.27 | 10.56 |
East | Girl | Golf | 1/31/2005 | 10 | 12.12 | 11.95 |
East | Girl | Fancy | 1/31/2005 | 10 | 13.74 | 13.33 |
West | Boy | Tee | 1/31/2005 | 11 | 11.44 | 10.94 |
West | Boy | Golf | 1/31/2005 | 11 | 12.63 | 11.73 |
West | Boy | Fancy | 1/31/2005 | 11 | 12.06 | 11.51 |
West | Girl | Tee | 1/31/2005 | 15 | 13.42 | 13.29 |
West | Girl | Golf | 1/31/2005 | 15 | 11.48 | 10.67 |
Etc. |
We might want to know how many Units did we sell in each Region for every Ship Date?And get a result like:
Region | 1/31/2005 | 2/1/2005 | 2/2/2005 | 2/3/2005 | 2/4/2005 |
---|---|---|---|---|---|
East | 66 | 80 | 102 | 93 | 114 |
North | 86 | 91 | 95 | 88 | 107 |
South | 73 | 78 | 84 | 76 | 91 |
West | 92 | 103 | 111 | 104 | 123 |
It takes 3 quantities to pivot the original table into the summary result, two columns andan aggregate of a third column. In this case the two columns are Region and Ship Date, thethird column is Units and the aggregate is Sum
Basic usage
The pivot function
Pivot tables are generated by the pivot function, which takes a Model and 3 attribute names,to make a pivot table like the example above:
The result is a ValuesQuerySet, which means the objects returned are dictionaries. Eachdictionary has a key for the row (‘shipped’ dates in this case) and a key for every valueof the column (‘region’ in this case).
The first argument can be a Model, QuerySet, or Manager. This allows you to generate a pivottable filtered by another column. For example, you may want to know how many units were soldin each region for every shipped date, but only for Golf shirts:
![Pivot 1.0.2 download windows 7 Pivot 1.0.2 download windows 7](/uploads/1/2/7/6/127643353/173210457.png)
The pivot function takes an optional parameter for how to aggregate the data. For example,instead of the total units sold in each region for every ship date, we might be interested inthe average number of units per order. Then we can pass the Avg aggregation function
If your data is stored across multiple tables, use Django’s double underscore notationto traverse foreign key relationships. For example, instead of the ShirtSales model havinga region attribute, it might have a foreign key to a Store model, which in turn has aforeign key to a Region model, which has an attribute called name. Then our pivot call lookslike
It’s also possible that the data column we are aggregating over should be a computed column.In our example ShirtSales model we are storing the number of units and the price perunit, but not the total cost of the order. If we want to know the average order size indollars in each region for every ship date, we can pivot the ShirtSales table:
If the rows should be grouped on a compound column, for example, you want to know how manyUnits were sold on each ship date not just split by region, but the combination of regionand gender, you can pass a list to the first argument:
To change the way the row keys are displayed, a display_transform function can be passed tothe pivot function. display_transform is a function that takes a string and returns a string.For example, instead of getting the results with North, East, South, and West for the regionsyou want them all lower cased, you can do the following
If there are no records in the original data table for a particular cell in the pivot result,SQL will return NULL and this gets translated to None in python. If you want to get zero, orsome other default, you can pass that as a parameter to pivot:
The above call ensures that when there are no units sold in a particular region on a particulardate, we get zero as the result instead of None. However, the results will only containshipped dates if at least one region had sales on that date. If it’s necessary to get resultsfor all dates in a range including dates where there are no ShirtSales records, we can passa target row_range:
Will output a result with every shipped date from Jan 1st to February 28th whether there aresales on those days or not.
The histogram function
This library also supports creating histograms from a single column of data with thehistogram function, which takes a Model, a single attribute name and an iterable of left edgesof bins.
Like pivot, the first argument can be a Model, QuerySet, or Manager. The result is alist of dictionaries:
It’s also possible to get several histograms from a single query by slicing the data on oneof the columns. For example, instead of the histogram above, we might want two histograms,one for boys and one for girls. The gender column of ShirtSales has two values,'Boy' and 'Girl'. Passing the gender column as a 4th optional parameter to histogramwill slice the data on that column.
The result is a ValuesQuerySet where each row corresponds to one bin
Installation
Just:
put django_pivot in installed apps in your settings file, and then you:
And off you go.
Tests
The test suite is run by Traviswith Django versions 1.11, 2.0 and 2.1 and backends sqlite, MySQL, and Postgres. If youwant to run the test suite locally, from the root directory:
That will use sqlite as the backend and whatever version of Django you havein your current environment.
License
MIT
Copyright 2017 Brad Martsberger
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release historyRelease notifications
1.8.1
1.8.0
1.7
1.6.1
1.6
1.5
1.4.1
1.4
1.3
1.2
1.0.2
1.0.1
1.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size django_pivot-1.8.1-py3-none-any.whl (14.2 kB) | File type Wheel | Python version py3 | Upload date | Hashes |
Filename, size django-pivot-1.8.1.tar.gz (14.1 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for django_pivot-1.8.1-py3-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | 9bf83b2b61d4dc95c01e5b7a595ee223c5c1f08a4590733673a306b1513174d4 |
MD5 | aefdcc0063851e9a6901a43c8c05eb30 |
BLAKE2-256 | e9a959f23651ef9c2ac663016103e00ca765d1e92b4d278ec7eeed140321e273 |
Hashes for django-pivot-1.8.1.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | 7184d3e3f5e96003150428bea106a9963f49f0431fa56f93595316c9b42bcca6 |
MD5 | 87aac3f02a0c392ff0569628d17f0116 |
BLAKE2-256 | 418dc799ab511ea700e714b93b533fc45e7a4c8b4ea780cfedae7cc60f8849fe |
-
Latest Version:Pivot Animator 4.2.8 LATEST
-
Requirements:Windows XP / Vista / Windows 7 / Windows 8 / Windows 10 / Windows XP64 / Vista64 / Windows 7 64 / Windows 8 64 / Windows 10 64
-
Author / Product:Peter Bone / Pivot Animator
-
Old Versions:
-
Filename:Pivot-Animator-4.2.8.exe
-
MD5 Checksum:6ac8168448e86444a4714cfa5a64b169
-
Details:Pivot Animator 2020 full offline installer setup for PC 32bit/64bit
Pivot Animator for Windows PC lets you develop 2D stick-figure sprite animations. The controls are simple enough to use.
Good features
When working with the program, the stick figure is positioned in the middle of the work environment. The timeline can be used to preview the animation based on the sequence of the frames. To learn more about the program, there is a help manual available online.
Controls
The red buttons let you control the working environment and the position where you drag the stick figure to. Other controls include flipping the figure, seeing onion skins, mirroring the figure, changing the figure color, and raising or lowering the selected figure.
The selected figure can be scaled or joined with another one. The opacity can be adjusted, and the frames can be pasted, deleted, or copied. When you’re ready to play the animation, you can have loop mode activated to keep the frames recycled. You can include a customized background picture that is in GIF, PNG, JPG, or BMP format.
Stick Figure Builder
You can create your own stick figures by using the circles and lines options. Other options include thickness adjusting, segment duplication, static generation, and more.
Export
The program lets you save and export in PIV format. This lets you import and edit your stick figure creations in the future. If you want to export in a different format, you can choose GIF, JPEG, PNG, or AVI as well. This lets you use them on web pages as image or video content.
Animation Creator
Pivot Animator does not have as many features as Adobe Animate or Autodesk Maya, but it has easy to use controls. People with any experience level will find the program to be comfortable to use. The results are impressive too.
Also Available: Download Pivot Animator for Mac
Good features
When working with the program, the stick figure is positioned in the middle of the work environment. The timeline can be used to preview the animation based on the sequence of the frames. To learn more about the program, there is a help manual available online.
Controls
The red buttons let you control the working environment and the position where you drag the stick figure to. Other controls include flipping the figure, seeing onion skins, mirroring the figure, changing the figure color, and raising or lowering the selected figure.
The selected figure can be scaled or joined with another one. The opacity can be adjusted, and the frames can be pasted, deleted, or copied. When you’re ready to play the animation, you can have loop mode activated to keep the frames recycled. You can include a customized background picture that is in GIF, PNG, JPG, or BMP format.
Stick Figure Builder
You can create your own stick figures by using the circles and lines options. Other options include thickness adjusting, segment duplication, static generation, and more.
Export
The program lets you save and export in PIV format. This lets you import and edit your stick figure creations in the future. If you want to export in a different format, you can choose GIF, JPEG, PNG, or AVI as well. This lets you use them on web pages as image or video content.
Animation Creator
Pivot Animator does not have as many features as Adobe Animate or Autodesk Maya, but it has easy to use controls. People with any experience level will find the program to be comfortable to use. The results are impressive too.
Also Available: Download Pivot Animator for Mac
![](/uploads/1/2/7/6/127643353/281515129.jpg)