python - Printing Lists as Tabular Data -


i quite new python , struggling formatting data nicely printed output.

i have 1 list used 2 headings, , matrix should contents of table. so:

teams_list = ["man utd", "man city", "t hotspur"] data = np.array([[1, 2, 1],                  [0, 1, 0],                  [2, 4, 2]]) 

note heading names not same lengths. data entries integers, though.

now, want represent in table format, this:

            man utd   man city   t hotspur   man utd         1          0           0  man city         1          1           0 t hotspur         0          1           2 

i have hunch there must data structure this, cannot find it. have tried using dictionary , formatting printing, have tried for-loops indentation , have tried printing strings.

i sure there must simple way this, missing due lack of experience.

some ad-hoc code python 2.7:

row_format ="{:>15}" * (len(teams_list) + 1) print row_format.format("", *teams_list) team, row in zip(teams_list, data):     print row_format.format(team, *row) 

this relies on str.format() , format specification mini-language.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -