I have written a script that splits a few txt files and stores them into xlsx files to be uploaded to another application. The excel files have a column B that NEEDS TO BE IN SHORT DATE FORMAT or else the upload fails. I have tested this rigorously. Ive tried everything I can think of. Here is an example of what is happening.
Date |
---|
03/31/2021 |
The data aboveis what my python file outputs. I need this to be in short date in excel. I notice the output comes out indented to the left which is odd for excel. When I click into a cell in this column and hit enter it comes out like this. It will now be in Short date format and can be uploaded. I have no idea how to format this column into the proper short date.
Date |
---|
3/31/2021 |
Thank you in advance for any assistance, I need to get column B into short date format from python.
EDIT showing script:
This is the script im using
df['CYCLE_DATE']=df['CYCLE_DATE'].dt.strftime('%m/%d/%Y')
this line changes the txt file output. The TXT file gives something like this 3/31/2021 0:00:00
Ive tried something like this as well
writer = pd.ExcelWriter("test.xlsx", engine='xlsxwriter')
tdf.to_excel(writer, sheet_name='s1', index=None, header=True)
workbook = writer.book
worksheet = writer.sheets['s1']
formatdict = {'num_format':'mm-dd-yy'}
fmt = workbook.add_format(formatdict)
worksheet.set_column('B:B', None, fmt)
writer.save()
Does not work.