1

So, my question may sound silly because this is the first time I'm using XlsxWriter. I straight up copied their code from their site but it didn't work.

The code is this:

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

# Get the xlsxwriter objects from the dataframe writer object.
workbook  = writer.book
worksheet = writer.sheets['Sheet1']

workbook  = xlsxwriter.Workbook('filename.xlsx')
worksheet = workbook.add_worksheet()

Even before I could start dealing with CSV files, this basic first run failed, and the following error appeared:

NameError: name 'xlsxwriter' is not defined

I tried using pip install openpyxl as someone said in this previous thread, but it didn't work either. Can someone give me a hand here please?

1 Answers1

0

If you are going to use xlsxwriter directly, outside of Pandas, like you are doing in the last 2 lines of the code above, you will need to import the module in order to use it:

import xlsxwriter
# ... Rest of your code as above.
jmcnamara
  • 38,196
  • 6
  • 90
  • 108
  • Yeah, i'm doing that. I just forgot to paste it. The problem is that every CSV is saved as a distict worksheet. And I don't want that. I need to save all of those CSVs in one single sheet and I need to specify the distance between them –  Nov 02 '20 at 23:10