[Python] How to take multiple arrays and turn them into vertical tables?

Discussão em 'Python' iniciado por Stack, Agosto 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am using numpy and matplotlib, I have multiple arrays:

    products = np.array(["laptop","smartphone","tablet"])
    price = np.array([2999.99,1099.99,1009.99])
    storage_space_MB = np.array([1500000,64000,512000])
    quantity=np.array([8,20,16])


    I am trying to turn these arrays into something that looks like:

    Product Name Price Storage Space (MB) Quantity
    ==============================================================================
    laptop 2999.99 1500000 8
    smartphone 1099.99 64000 20
    tablet 1009.99 512000 16


    So far I have tried:

    header= f"{'Product Name':<{23}}{'Price':<{col_width}}{'Storage Space (MB)':>{col_width}}{'Quantity':>{col_width}}"
    line = "="*72
    print(header)
    print(line)
    print(" ")


    which successfully worked for printing the headers and the line of equal symbols, however when I try a similar thing using the defined arrays:

    f"{products:<{23}}{price:<{col_width}}{storage_space_MB:>{col_width}}{quantity:>{col_width}}"


    it produces the error code:

    unsupported format string passed to numpy.ndarray.__format__


    I have also made some other attempts using .reshape however I could not get that to work properly

    Continue reading...

Compartilhe esta Página