1 回答
TA贡献1834条经验 获得超8个赞
它应该工作。在获得对工作簿对象的引用后,您需要add_format()稍后在代码中移动它。这是一个例子:
import pandas as pd
# Create a Pandas dataframe from some data.
df = pd.DataFrame({'Data': [1234.56, 234.56, 5678.92]})
# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('pandas.xlsx', engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
df.to_excel(writer, sheet_name='Sheet1')
# Get the xlsxwriter workbook and worksheet objects.
workbook = writer.book
worksheet = writer.sheets['Sheet1']
# Set a currency number format for a column.
num_format = workbook.add_format({'num_format': '#,###'})
worksheet.set_column('B:B', None, num_format)
# Close the Pandas Excel writer and output the Excel file.
writer.save()
输出:
添加回答
举报