osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using zip for transpose


On 21/02/2019 13:49, Peter Otten wrote:
> Robin Becker wrote:
> 
>.......


> Isn't df.values a numpy array? Then try the more direct and likely more
> efficient
> 
> df.values.tolist()
> 
> or, if you ever want to transpose
> 
> df.values.T.tolist()
> 
> The first seems to achieve what your sample code does. (In addition it also
> converts the numpy type to the corresponding python builtin, i. e.
> numpy.float64 becomes float etc.)
> 
Thanks for the pointer.

In fact we were working through all the wrong methods eg iterrows (slow) or iterating over columns which created the need for a
transpose.

However, df.values.tolist() seems to create a list of row lists which is what is actually needed and it is the fastest.
So to convert df to something for reportlab table this seems most efficient

rlab_table_data=[['Mean','Max','Min','TestA','TestB']]+df.values.tolist()

thanks again
-- 
Robin Becker