使用xlsxwriter时,Python日期时间变为浮动状态

时间:2018-02-22 13:54:40

标签: python excel pandas dataframe xlsxwriter

以下是我在excel表中编写数据框的for循环

for i in range(1,len(sorted_tasks[sorted_tasks.columns[0]])):
    ls = list(sorted_tasks.loc[i])
    if sorted_tasks['Age'][i]>=10 and type_of_breach(sorted_tasks['Expected Delivery Date'][i]) != 'y':
        worksheet.write_row(i,0,ls,format_green)
    elif type_of_breach(sorted_tasks['Expected Delivery Date'][i])=='y' and sorted_tasks['Age'][i]>=10:
        worksheet.write_row(i,0,ls,format_orange)
    elif type_of_breach(sorted_tasks['Expected Delivery Date'][i])=='y':
        worksheet.write_row(i,0,ls,format_yellow)
    elif type_of_breach(sorted_tasks['Expected Delivery Date'][i])=='r':
        worksheet.write_row(i,0,ls,format_red)
    else:
        worksheet.write_row(i,0,ls,format_normal)

This is how I am getting it though the calculation are correct I want this to be in this format

1 个答案:

答案 0 :(得分:0)

Excel中的日期由具有格式的数字表示。如果你没有提供日期格式,你只需要一个数字/浮点数。

没有工作程序很难说,但您可能需要在XlsxWriter代码中添加日期格式。有关详细信息,请参阅XlsxWriter文档中的Working with Dates and TimeDefault Date Formatting