python - Trying to pass filename to ExcelWriter -
i trying pass customized filename variable excelwriter cannot excelwriter portion of work reason. if replace "sheetname" "temp.xlsx" in excelwriter function works, i'm not able pass variable function. need able store today's date in filename every time script run.
spreadsheet = pandas.dataframe() sheetname = 'makino machine metrics ' + time.strftime("%m/%d/%y") +'.xlsx' writer = pandas.excelwriter(sheetname, engine = 'xlsxwriter') spreadsheet.to_excel(writer, sheet_name= 'results',index = false) workbook = writer.book worksheet = writer.sheets['results'] writer.save()
thanks in advance help
when run program following error:
ioerror: [errno 2] no such file or directory: 'makino machine metrics 07/12/2016.xlsx'
you can fix removing forward slashes date part:
import pandas import time spreadsheet = pandas.dataframe() sheetname = 'makino machine metrics ' + time.strftime("%m_%d_%y") +'.xlsx' writer = pandas.excelwriter(sheetname, engine = 'xlsxwriter') spreadsheet.to_excel(writer, sheet_name='results', index=false) workbook = writer.book worksheet = writer.sheets['results'] writer.save()
looks error comes open:
>>> open('12/12/12.xlsx', 'w') traceback (most recent call last): file "<stdin>", line 1, in <module> ioerror: [errno 2] no such file or directory: '12/12/12.xlsx'
so, either escape characters or use character in date, in example above.
Comments
Post a Comment