How do I output lists as a table in Jupyter notebook?

后端 未结 11 1239
灰色年华
灰色年华 2021-01-30 09:51

I know that I\'ve seen some example somewhere before but for the life of me I cannot find it when googling around.

I have some rows of data:

data = [[1,2         


        
11条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 10:26

    If you don't mind using a bit of html, something like this should work.

    from IPython.display import HTML, display
    
    def display_table(data):
        html = ""
        for row in data:
            html += ""
            for field in row:
                html += ""
        html += "

    %s

    "%(field) html += "
    " display(HTML(html))

    And then use it like this

    data = [[1,2,3],[4,5,6],[7,8,9]]
    display_table(data)
    

提交回复
热议问题