Package: table-maker
Table MakerDescriptionMake simple tables from rows and columns, with values separated into cells and the contents left-justified.Initially designed for creating map marginalia in QGIS and ArcMap, as well as a susbtitute for the often over-engineered and clunky table wizards that are featured in word processors.InstallationAt some point:pip install table_makerUsageMost basic use is to create a simple, cleanly-formatted table:>>>fromtable_makerimportmake_table>>>cols=('athlete','time')>>>rows=(('Clint','16:04'),('Mitch','12:12'),('Tommy','22:57'),('Zach','27:56'))>>>print(make_table(cols,rows,sort_col=1))+--------+--------+|athlete|time|+========+========+|Mitch|12:12|+--------+--------+|Clint|16:04|+--------+--------+|Tommy|22:57|+--------+--------+|Zach|27:56|+--------+--------+That's mostly it, but it does have a few simple utilities, for example, you can add some row numbers if you like:>>>importtable_makerastm>>>cols=('u-boat','commissioned','sunk')>>>rows=(...('u-64','16 Dec 39','13 Apr 40'),...('u-104','19 Aug 40','28 Nov 40'),...('u-107','08 Oct 40','08 Aug 44'))>>>uboats=tm.insert_row_numbers(tm.make_table(cols,rows))>>>print(uboats)+--------------+--------------+--------------+|u-boat|commissioned|sunk|+==============+==============+==============+1|u-64|16Dec39|13Apr40|+--------------+--------------+--------------+2|u-104|19Aug40|28Nov40|+--------------+--------------+--------------+3|u-107|08Oct40|08Aug44|+--------------+--------------+--------------+Or you can remove separators from the rows if you want a more compact table, and convert items to title case if you like:>>>importtable_makerastm>>>cols=('album','year')>>>rows=(('fandango!','1975'),('tres hombres','1973'),('eliminator','1983'))>>>x,y=tm.capitalize_inputs(cols,rows)>>>print(tm.remove_seps(tm.make_table(cols=x,rows=y,scaling=1.1,sort_col=1)))+--------------+--------------+|Album|Year|+==============+==============+|TresHombres|1973||Fandango!|1975||Eliminator|1983|+--------------+--------------+There are no utilities for selecting rows, you are better off doing that ahead of time.
For example let's say you want to make a table like from this string:>>>csv='''first,last,GOATscore,rankKareem,Abdul-Jabbar,5.600LeBron,James,5.511Michael,Jordan,5.219Tim,Duncan,4.273Bill,Russell,4.066Kobe,Bryant,4.021Wilt,Chamberlain,3.885Karl,Malone,3.823Shaquille,O'Neal,3.820Julius,Erving,3.502...'''Then you only want players whose score is above 4, it's easiet to get that before creating the table:>>>importtable_makerastm>>>cols=csv.split()[0].split(',')>>>rows=[item.split(',')foritemincsv.split('\n')[1:]ifitem]>>>above_4=[rowforrowinrowsiffloat(row[2])>4]>>>table=tm.make_table(cols,above_4,sort_col=-1,reverse=True,scaling=1.25)>>>print(tm.insert_title("   the greatest of all time",tm.insert_row_numbers(table)))THEGREATESTOFALLTIME+---------------+---------------+---------------+|first|last|GOATscore|+===============+===============+===============+1|Kareem|Abdul-Jabbar|5.600|+---------------+---------------+---------------+2|LeBron|James|5.511|+---------------+---------------+---------------+3|Michael|Jordan|5.219|+---------------+---------------+---------------+4|Tim|Duncan|4.273|+---------------+---------------+---------------+5|Bill|Russell|4.066|+---------------+---------------+---------------+6|Kobe|Bryant|4.021|+---------------+---------------+---------------+Alternatively, you could use thetransformfunction to convert the table into a dictionary, which is conveniently designed to be compatible with thepandas.DataFrame.from_dict()method, turn it into a dataframe and process it that way.