download pandas data set from Python notebook into local

Options
saraa1
saraa1 Registered Posts: 13 ✭✭✭

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

Answers

  • EliasH
    EliasH Dataiker, Registered Posts: 34 Dataiker
    Options

    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

  • saraa1
    saraa1 Registered Posts: 13 ✭✭✭
    Options

    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 ?

  • VitaliyD
    VitaliyD Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer Posts: 102 Dataiker
    edited July 17
    Options

    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

Setup Info
    Tags
      Help me…