Skip to main content

Pivot tables for CSV files in the terminal.

Tested on Python 3.6 and 2.7.

Installing

pip install csvpivot

Usage

Say you have a CSV file such as:

name,country,gender,salary Oliver,UK,M,10000 Jack,UK,M,21000 Emily,UK,F,32000 Harry,UK,M,43000 Adam,France,M,54000 Paul,France,M,65000 Louise,France,F,76000 Alice,France,F,87000 Emma,Germany,F,98000

We could then find the average salary in each country:

$ csvpivot test.csv –rows country –values ‘mean(salary)’

country,mean(salary) France,70500 Germany,98000 UK,26500

It would be useful to find out the maximum and minimum values too though:

$ csvpivot test.csv –rows country –values ‘mean(salary)’ ‘min(salary)’ ‘max(salary)’

country,mean(salary),min(salary),max(salary) France,70500,54000,87000 Germany,98000,98000,98000 UK,26500,10000,43000

As well as mean, min, and max, CSV Pivot also supports median, sum, stddev, count, countuniq, concat, and concatuniq. All require numerical values apart from the last two. If numbers contain commas they are interpreted as thousands separators and removed.

Columns are also supported. So we could break down our data by gender:

$ csvpivot test.csv –rows country –values ‘mean(salary)’ –columns gender

country,mean(salary):F,mean(salary):M France,81500,59500 Germany,98000, UK,32000,24666.666666666668

Metadata

Release files for csvpivot 1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csvpivot 1.4
File Size Uploaded
csvpivot-1.4.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for csvpivot 1.4
File Interpreter ABI Platform
csvpivot-1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 9.7 kB

Release files / csvpivot-1.4.tar.gz

Download URL csvpivot-1.4.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e3963769e2575345711b98587997d68b758915aec8b9194a073f572571659b5a
BLAKE2b-256 checksum
How to use checksums
3548ba02f11fcbed83ee93c2dd84571d45beb7086a5b1e39c96aeda0a01eff8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / csvpivot-1.4-py2.py3-none-any.whl

Download URL csvpivot-1.4-py2.py3-none-any.whl
Size 5.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
928a7ec23027227296bc855c76d7cb2077863585795280caf19d59d3253e58a0
BLAKE2b-256 checksum
How to use checksums
d062dffa4c06376b76cb6212a5d6c7bda2631e2b290ab1de715ad21bbb77f443
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.4 This release

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page