Reputation: 61
I am trying to save the content of pandas dataframe to excel file in windows/azure databricks. import pandas as pd
df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')
writer.save()
Error >>
ModuleNotFoundError: No module named 'xlsxwriter'
at line #2 pd.ExcelWriter()
databricks cluster is running on spark 2.4.4 Any suggestion on how to fix this ?
Upvotes: 3
Views: 10052
Reputation: 379
you can check the documentation.
enginestr (optional)
Engine to use for writing. If None, defaults to io.excel..writer. NOTE: can only be passed as a keyword argument.
Deprecated since version 1.2.0: As the xlwt package is no longer maintained, the xlwt engine will be removed in a future version of pandas.
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.ExcelWriter.html
Upvotes: 0
Reputation: 1100
Make sure you have XlsxWriter installed
pip install XlsxWriter
you might need to restart the kernel
also, remember to import
import pandas as pd
import xlsxwriter
df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')
writer.save()
Upvotes: 8