Pandas 如何在数据框的html导出中设置间距?

Pandas 如何在数据框的html导出中设置间距?,pandas,Pandas,我正在尝试修改并获得更多的列间距 import pandas as pd df = pd.DataFrame({'A': [1,10], 'B': ['B','BBBBBB'], 'C': [0,1000], 'D': ['D','DDDDDD']}) #https://stackoverflow.com/a/5667535/3014199 spacing = dict(sele

我正在尝试修改并获得更多的列间距

import pandas as pd

df = pd.DataFrame({'A': [1,10],
                   'B': ['B','BBBBBB'],
                   'C': [0,1000],
                   'D': ['D','DDDDDD']})

#https://stackoverflow.com/a/5667535/3014199
spacing = dict(selector="table",props=[('border-collapse', 'separate'), 
                                       ('border-spacing',  '100px 500px')])

# Style
result=df.style.set_properties(subset=df.columns[[0,2]], **{'text-align':'right'})\
               .set_properties(subset=df.columns[[1,3]], **{'text-align':'left'})\
               .set_table_styles([spacing])

print(result.render(),file=open('test.html','w'))
但是,尽管这些列的值很荒谬,但它们之间似乎没有进一步的区别

set\u properties
中添加例如
“padding-right”:“10px”
似乎很有效,但我想把事情做好


(还有,我如何抑制索引,它是
index=False
。\u html
但是放在哪里?

您必须跳过
selector=“table”
才能将属性分配给

使用
selector=“table”
为表中的表分配


你可以用

result.render(head=[])` 
跳过页眉,但仍有
在使用
'border-space'

使用

dict(selector="thead", props = [('display', 'none')])
您可以隐藏

您还可以使用skip
head=[]
,它会将头保存在文件中,但您不会看到它们




顺便说一句:我签入了源代码:
render()
使用模板
to_html()
使用非常复杂的方法来呈现html(即它使用类)。

您必须跳过
selector=“table”
才能将属性分配给

使用
selector=“table”
为表中的表分配


你可以用

result.render(head=[])` 
跳过页眉,但仍有
在使用
'border-space'

使用

dict(selector="thead", props = [('display', 'none')])
您可以隐藏

您还可以使用skip
head=[]
,它会将头保存在文件中,但您不会看到它们




顺便说一句:我签入了源代码:
render()
使用模板
to_html()
使用非常复杂的方法来呈现html(即,它使用类)。

我更喜欢使用引导来呈现空间

# Creates the dataframe
df = pd.DataFrame(myData)

# Parses the dataframe into an HTML element with 3 Bootstrap classes assigned.
tables=[df.to_html(classes='table table-hover', header="true")]

在本例中,我使用Bootstrap中的类“”,我更喜欢使用Bootstrap作为空间

# Creates the dataframe
df = pd.DataFrame(myData)

# Parses the dataframe into an HTML element with 3 Bootstrap classes assigned.
tables=[df.to_html(classes='table table-hover', header="true")]
在本例中,我使用了Bootstrap中的类“”