download pandas data set from Python notebook into local

saraa1
Level 2
download pandas data set from Python notebook into local

Hello DSS community,

could it be possible to download a panda's dataset from a python notebook into a local computer?

Without doing clicking into the button shown on the picture 

 

thank you :))

Capture.PNG

0 Kudos
3 Replies
EliasH
Dataiker

Hi @saraa1 ,

This is surely possible, as this is a pandas dataframe you can utilize the pandas API to do this. 

For example, if you would like to download this dataframe as a csv file, you can use:

df.to_csv('out.csv')

You can find this file at

<YOUR_DATA_DIR>/jupyter-run/dkuworkdirs/<YOUR_PROJECT_KEY>/<NAME_OF_NOTEBOOK_WITH_ADDED_ID>/out.csv

- Elias

0 Kudos
saraa1
Level 2
Author

Hello Elias,

Thank you for your answer,

but this does not work on a jupyter notebook on DSS, while I'm not admin,

maybe, I could try to save the file on DSS folders !!! This could be also a solution and a way to keep me on DSS environment as well,

but how to do so then ? 

0 Kudos
VitaliyD
Dataiker

Hello @saraa1,

Assuming you want to save the data frame without clicking a button in CSV format, you can use javascript to open the link client-side. Please refer to the code example below:

import base64
from io import BytesIO
from IPython.display import Javascript

def save_df( df, filename = "data.csv"):  
    csv = df.to_csv()
    b64 = base64.b64encode(csv.encode())
    payload = b64.decode()
    url="data&colon;text/csv;base64,{payload}".format(payload=payload)
    display(Javascript('window.open("{url}");'.format(url=url)))
    
save_df(mydataset_df)

Hope this is what you were looking for.

Best,

Vitaliy

0 Kudos