rt3x.de NoPaste

Python prettytable example

This is a nopaste service, powered by Flying Paste.

Author: Malte Bublitz
Language/File type: Python 3

Description

A short example for prettytable[1] showing the population for my hometown Bergkamen, both total and per district.

[1]: https://pypi.org/project/prettytable/

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import prettytable

bergkamen = prettytable.PrettyTable()
bergkamen.field_names = ["Year", "Total ", "Mitte", "Oberaden", "Weddinghofen", "Rünthe", "Overberge", "Heil"]
bergkamen.add_rows(
	[
		[2000, 52732, 18074, 13120, 10188, 7185, 3647, 515],
		[2001, 52714, 17937, 12997, 10338, 7225, 3712, 503],
		[2002, 52607, 17983, 12793, 10377, 7198, 3744, 511],
		[2003, 52353, 17996, 12678, 10306, 7162, 3709, 502],
		[2004, 52329, 18169, 12571, 10242, 7152, 3698, 496],
		[2005, 52021, 18109, 12317, 10212, 7105, 3772, 506],
		[2006, 52020, 18069, 12391, 10211, 7076, 3800, 483],
		[2007, 51755, 17969, 12323, 10182, 6991, 3813, 477],
		[2008, 51467, 17932, 12266, 10082, 6914, 3791, 482],
		[2009, 51158, 17940, 12136,  9935, 6868, 3799, 480],
		[2010, 50605, 17728, 11956,  9815, 6842, 3790, 474],
		[2011, 50274, 17583, 11921,  9740, 6792, 3749, 483],
		[2012, 49957, 17462, 11898,  9635, 6757, 3751, 470],
		[2013, 49587, 17284, 11730,  9657, 6712, 3709, 495],
		[2014, 49637, 17359, 11696,  9666, 6724, 3682, 510],
		[2015, 50035, 17300, 11703, 10110, 6726, 3676, 520],
		[2016, 50161, 17350, 11820, 10053, 6740, 3673, 525],
		[2017, 50443, 17394, 12124, 10052, 6694, 3647, 532],
		[2018, 50339, 17427, 12094,  9972, 6682, 3636, 528],
		[2019, 50407, 17479, 12110,  9994, 6671, 3621, 532]
	]
)


def main():
	# print(bergkamen.get_csv_string())
	print(bergkamen)


if __name__ == "__main__":
    main()