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!
igro
January 24, 2019, 4:54pm
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.
@igro :
Is there any way to create the files in \FileUploader\new directory?
igro
February 1, 2019, 10:13am
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))
1 Like