0

I want to save data-frame as excel file using project-lib for Python in IBM Watson Studio.

The tutorial shows example for csv file, which works. But when I try to do the same for excel it needs to do more actions which I couldn't know.

from pandas import ExcelWriter
excel_writer = pd.ExcelWriter("1.xlsx")
project.save_data(data=df_4.to_excel(excel_writer), file_name="1.xlsx", overwrite=True)

I expect to have saved dataframe(df_4) as excel in project assets area in IBM Watson.

Mikku
  • 6,538
  • 3
  • 15
  • 38

1 Answers1

0

You may need to save the file as a binary file:

import io

filename = ‘thefilename’
with open(filename, 'rb') as z:
        data = io.BytesIO(z.read())
        project.save_data(
            filename, data, set_project_asset=True, overwrite=True
        )

Instead of using the excelwriter, you may want to use the code above for uploading .xlsx file as a binary file to the project assets.

You may also like to look at the following video for modifying and saving the .xlsx file and then you can use the binary file method code to upload your modified .xlsx file onto the IBM Cloud.

Code excerpt from: Similar Post

Python - Read and Write Multiple Sheets to Pandas Dataframe

Hope this helps!