I have one giant csv file that contains a year worth intraday data of a stock, as it is too big to analyse, I would like to process the data beforehand.
I want to break it down into 12 excel files (12 months), each one would have 28-31 sheets/tabs/pages that contains that intraday data for that date. Hence I have prepared these excel files with names Stock-01, Stock-02 until Stock-12, they are empty at the moment, waiting for data to append by my python code.
I am using the code below after I use read_csv:
for index in indexs:
name = "Stock_" + index.strftime("%y-%m-%d")
work = data[data.index.date == index].copy()
columnsTitles = ['Volume','Open','High','Low','Close']
work = work.reindex(columns= columnsTitles)
filepath = "Stock-{}.xlsx".format(index.strftime("%m"))
writer = ExcelWriter(filepath, engine='openpyxl')
work.to_excel(writer, index = True, sheet_name=name)
writer.save()
writer.close()
del work
My approach is, indexs contains all the dates, hence running through using index, i select the prepared excel file, append a sheet with the name using the date (index), and copy the dataframe directly using the simple to_excel function.
However, the result is, it has only one sheet, and this sheet has the last date data. (One possible reason may be the program is creating a new workbook everytime rather than reading the existing workbook)
A similar question is asked, but that is working on another approach. I would like to write a dataframe directly to excel, but in this question, using xlsxwriter, I don't seem to be able to do it, as it accepts str value only.