beautifultable icon indicating copy to clipboard operation
beautifultable copied to clipboard

support for transposing tables

Open furlongm opened this issue 3 years ago • 3 comments

Similar to what was requested initially in #90:

This would be useful where there are too many headers to fit in the terminal, but only a few rows. Something along the lines:

print(table.transposed())

would be super helpful.

Now that there are row headers, the transpose function would convert column headers to row headers (or vice versa) and transpose the data matrix.

Similar to numpy's transpose: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html

furlongm avatar Jul 31 '20 20:07 furlongm

See also https://www.geeksforgeeks.org/transpose-matrix-single-line-python/ for other examples.

furlongm avatar Jul 31 '20 20:07 furlongm

I feel this would be too niche. Why not build the table columnwise directly instead of building it row by row and then transposing. let me know if I'm missing something. Also several decisions would have to made w.r.t. transposing.

  • What happens to column attributes such as alignment, padding, etc. should they just be dropped?
  • What to do if the table has custom styling characters? Should we also try to transpose them?

I personally feel that beautifultable needs a method that takes a list of list and creates the table from that. Currently you have to iterate through them one by one and then append them as rows. Then a user could just instead pass something like list(zip(*data))) to that method if they want the data transposed. Although I'm definately open to a better suggestion.

pri22296 avatar Aug 03 '20 09:08 pri22296

Hi @pri22296 , Actually I also felt this requirement some time ago. Maybe we can provide a method to transpose the beautiful table object. I need to look at the code but we can try to transpose every attribute of column and rows.

Agent-Hellboy avatar Apr 01 '22 07:04 Agent-Hellboy