将 Pandas Dataframe 作为 xlsx
文件保存到磁盘时,是否有任何方法可以保存它,以便保存字符串的列以左对齐方式保存,而不是默认的“中心”对齐方式?
我目前正在使用以下内容来保存我的 DataFRame
writer = pd.ExcelWriter(path_to_file)
df.to_excel(writer, 'Sheet1')
writer.save()
最佳答案
遗憾的是,目前无法在使用 Pandas to_excel()
写入数据时应用 Excel 格式。
使用 XlsxWriter 作为 Excel 编写引擎时,您可以应用列格式。请参阅Working with Python Pandas and XlsxWriter .
关于python - 将数据框保存到 xlsx 并左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22972156/