How can I export a list of DataFrames into one Excel spreadsheet?
The docs for
If passing an existing ExcelWriter object, then the sheet will be added to the existing workbook. This can be used to save different DataFrames to one workbook
writer = ExcelWriter("output.xlsx")
Following this, I thought I could write a function which saves a list of DataFrames to one spreadsheet as follows:
from openpyxl.writer.excel import ExcelWriter def save_xls(list_dfs, xls_path): writer = ExcelWriter(xls_path) for n, df in enumerate(list_dfs): df.to_excel(writer,"sheet%s" % n) writer.save()
However (with a list of two small DataFrames, each of which can save
to_excel individually), an exception is raised (Edit: traceback removed):
AttributeError: "str" object has no attribute "worksheets"
Presumably I am not calling
ExcelWriter correctly, how should I be in order to do this?
You should be using pandas own
from pandas import ExcelWriter # from pandas.io.parsers import ExcelWriter
save_xls function works as expected:
def save_xls(list_dfs, xls_path): with ExcelWriter(xls_path) as writer: for n, df in enumerate(list_dfs): df.to_excel(writer,"sheet%s" % n) writer.save()
If you’ve picked up this book, you’re probably aware of the extraordinary progress that deep learning has represented for the field of artificial intelligence in the recent past. In a mere five ye...
It’s in all of us. Data science is what makes us humans what we are today. No, not the computer-driven da...
The Apache Hadoop software library has come into it’s own. It is the basis for advanced distributed development for a host of companies, government institutions, and scientific research facilities. ...
The series “Studies in Big Data” (SBD) publishes new developments and advances in the various areas of Big Data-quickly and with a high quality. The intent is to cover the theory, research, develo...