Pandas to_excel -> Where does it go?


#1

If I have a pandas dataframe, is there an easy way to export it as an excel file into the project file?

If I run df.to_excel(“test.xlsx”), it saves it in the running Docker container, but it doesn’t show up in the project folder from the main screen.

Ideas?

Thanks!


#2

Hi, Parker!

Resulting *.xlsx file is attached to the workbook and can be found in the “Tools -> File Uploader” dialog from the workbook header or through “Attach Data” option from the File System view.


#3

@igro:

Is there any way to create the files in \FileUploader\new directory?


#4

The following code will do the trick:

import os
import pandas as pd
#%%
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
#%%
directory = 'new directory'
file = 'test.xlsx'
#%%
if not os.path.exists(directory):
    os.makedirs(directory)
#%%
df.to_excel(os.path.join(directory, file))

#5

@igro

duh! Thanks.