使用pandas.DataFrame.to_html时如何设置列宽? [英] How do I set the column width when using pandas.DataFrame.to_html?

查看:949
本文介绍了使用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时如何设置列宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆