本文介绍了使用pandas.DataFrame.to_html时如何设置列宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已阅读此,但我仍然对此感到困惑pandas.DataFrame.to_html
时如何设置列宽.
I have read this, but I am still confused about how I set the column width when using pandas.DataFrame.to_html
.
import datetime
import pandas
data = {'Los Angles': {datetime.date(2018, 9, 24): 20.5, datetime.date(2018, 9, 25): 1517.1},
'London': {datetime.date(2018, 9, 24): 0, datetime.date(2018, 9, 25): 1767.4},
'Kansas City': {datetime.date(2018, 9, 24): 10, datetime.date(2018, 9, 25): 1.4}}
df = pandas.DataFrame(data=data)
html = df.to_html()
上面的代码导致:
如何强制将列宽设置为相同?
How do I go about forcing the column width so that they are the same?
推荐答案
尝试一下:
import datetime
import pandas
data = {'Los Angles': {datetime.date(2018, 9, 24): 20.5, datetime.date(2018, 9, 25): 1517.1},
'London': {datetime.date(2018, 9, 24): 0, datetime.date(2018, 9, 25): 1767.4},
'Kansas City': {datetime.date(2018, 9, 24): 10, datetime.date(2018, 9, 25): 1.4}}
df = pandas.DataFrame(data=data)
pandas.set_option('display.max_colwidth', 40)
html = df.to_html()
这篇关于使用pandas.DataFrame.to_html时如何设置列宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!