I have two questions regarding writing dataframe data to a file:
My program produces summary statistics on many grouped rows of a dataframe and save those to a StringIO buffer which writes to my output.csv file at completion. I have a feeling the pd.concat would be better suited but I couldn't get that to work. I can try adding a snippet of code when I get a chance and hopefully someone can explain how to properly concat and I assume that will solve my issue.
That being said, my program works and that's more than I can ask for. What is bugging me though is how the CSV file ends up repeating the same column labels for every summary statistic dataframe that was written to the buffer and incidentally into my CSV file as well. Is there a way to only write the column labels once and avoid multiple duplicate label rows?
My second question is in regards to writing to Excel to skip an unnecessary copy and paste. Like my previous issue, this is only a minor hindrance but still bugs me as I would like to do things the right way. The issue is that i want all the frames written to the same sheet. In order to avoid overwriting the same data it is necessary to use a buffer to store the data until the end. None of the docs seemed to helpful in my particular situation. I devised a workaround: xlwt to buffer -> output.write(buffer.getvalue()) -> pd.to_csv(output) and then reimport that same file via pd.read_csv and finally add another writer that writes the dataframe to Excel. After all that work I ended just sticking with the simplicity of CSV since the Excel writer actually magnified the ugliness of the duplicating rows. Any suggestions on how my buffer issue can be handled better as I would prefer the streamline and control of Excel writer to a CSV output.
Sorry for not having any code for context. I tired my best to explain without it. If necessary I can add the code when I get a free chance.