i都使用imgkit创建一个由来自dataframe的HTML创建的图像的PDF。我需要整个特定行才能大胆[行:0和7],但尚未实现。我想念什么?
html = df.style
.set_properties(**{'width': 200, 'background-color': '#eae2d5',
'color': 'black', 'font-size': '14px',
'text-align': 'left'},
subset=['var1'])
.set_properties(**{'color': ' 33[1m'}, # BOLDING rows 1
subset=['var1'][0]) # Here is the error. .
.set_properties(**{'color': ' 33[1m'}, # BOLDING rows 7
subset=['var1'][7]) # Here is the error.
.set_properties(**{'width': 80, 'background-color': '#eae2d5',
'color': 'black', 'font-size': '14px',
'text-align': 'center'},
subset=['var3', 'var4'])
.set_table_styles([{'selector': 'thead',
'props': [('background-color', '#b2361e'),
('color', 'white'),
('font-size', '18px')]}, ])
.highlight_null(null_color='white').hide_index().render()
到目前为止,它说:" SyntaxError:持续字符后出乎意料的字符"
这是一个风格的问题,所以请随时用一粒盐来接受我的答案。
首先,我建议查看Python中的错误消息,以了解错误发生的特定行。这将极大地帮助我们,因为我们可能正在看错误的事情。例如,当我第一次尝试通过您的代码回复时,我的眼睛转到了这一行:
'color': ' 33[1m'
我不认为这是有效的颜色,因为您的后挡板是在0中作为逃生角色运行的。此外,我不确定[
会做什么。
第二,代码一般很难阅读,Python专注于可读性。您愿意重组代码以帮助解决问题吗?也许这样的东西?
https://stackoverflow.com/a/4768979/11323304
我希望这个答案会有所帮助,欢迎堆栈!