python:固定宽度列导出excel

问题描述 投票:0回答:1

data = {'Nom \n du collaborateur': ['Jude Bellingham']} df = pd.DataFrame(data) file_path = "/home/jovyan/workspaces/syne_ctl_prm/output/OUTPUT_EXCEL_FILE.xlsx" file_path df.to_excel(file_path, index = False)

你好 通过执行这段代码我得到一个excel文件。该列的 widtg 是 8。我想在我的 python 代码中将其修复为 20。 预先感谢您的帮助 亲切的问候 纳赛尔

python excel
1个回答
-1
投票

萨拉姆,

您可以通过简单地调整选项设置中的宽度来调整表格的宽度,如文档中所述。在 documentation 中搜索 display.max_colwidth

### Test data
df = DataFrame({'text': ['foo foo foo foo foo foo foo foo', 'bar bar bar bar bar'],
             'number': [1, 2]})

df.style.set_properties(subset=['text'], **{'width': '300px'})
© www.soinside.com 2019 - 2024. All rights reserved.