Apply CSS class to Pandas DataFrame using to_html

前端 未结 4 577
执笔经年
执笔经年 2020-11-28 21:46

I\'m having trouble applying \"classes\" argument with Pandas \"to_html\" method to style a DataFrame.

\"classes : str or list or tuple, default None CSS class(es) t

4条回答
  •  感情败类
    2020-11-28 22:01

    Here's how I did it

    Create a text file for css code and write down your css code here, say css_style.txt Now read this txt file as a string in your python file

    with open('css_style.txt', 'r') as myfile: style = myfile.read()

    Now in HTML code

    """Something Something{1}
    {0}
    """.format(some_panda_dataframe.to_html,style)

    Here in my case css_style.txt file is

    
    

提交回复
热议问题