[SciPy-user] Save column & row headers to csv file with something like savetxt?

Alan G Isaac aisaac@american....
Sun Dec 21 15:15:16 CST 2008


SimpleTable now supports column specific formatting.
Example below.

fwiw,
Alan Isaac

     >>> mydata = [[11,12],[21,22]]  #can be 2d array
     >>> myheaders = "Column 1", "Column 2"
     >>> mystubs = "Row 1", "Row 2"
     >>> tbl = text.SimpleTable(mydata, myheaders, mystubs, title="Title")
     >>> print tbl
              Title
     =======================
           Column 1 Column 2
     -----------------------
     Row 1    11       12
     Row 2    21       22
     -----------------------

     >>> # set column specific data formatting
     ... tbl = text.SimpleTable(mydata, myheaders, mystubs,
     ...     fmt={'data_fmt':["%3.2f","%d"]})
     >>> print tbl

     =======================
           Column 1 Column 2
     -----------------------
     Row 1  11.00      12
     Row 2  21.00      22
     -----------------------
     >>> print tbl.as_csv()

     ,"Column 1","Column 2"
     "Row 1",11.00,12
     "Row 2",21.00,22




More information about the SciPy-user mailing list