ModuleNotFoundError: No module named 'xlsxwriter' in databricks

Viewed 6285

I am trying to save the content of pandas dataframe to excel file in windows/azure databricks. import pandas as pd

Create a Pandas dataframe from the data.

df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})

Create a Pandas Excel writer using XlsxWriter as the engine.

writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')

Convert the dataframe to an XlsxWriter Excel object.

df.to_excel(writer, sheet_name='Sheet1')

Close the Pandas Excel writer and output the Excel file.

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 ?

2 Answers

Make sure you have XlsxWriter installed

 pip install XlsxWriter

you might need to restart the kernelenter image description here

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()

enter image description here

enter image description here

Related