0

I am trying to figure out how to download data from jupyter lab to the local download folder. Sample Code below. For my current code, the excel gets downloaded to the folder in lab. However, since the code will be used by others, the download needs to take place on their systems(download folder). How to add this option? I have tried using the "download_path = os.path.expanduser("~") + "/Downloads/"" optio but this saves it to the static folder

import pandas as pd
import numpy as np
import xlsxwriter

def create_dataframes():
    df = pd.DataFrame(np.array([["A", 2021, 200, 400], 
                                ["B", 2020, 600, 300],
                                ["A", 2021, 500, 250], 
                                ["B", 2030,  350, 432],
                                ["C", 2022,  250, 532],
                                ["C", 2022,  150, 232],]),
                      columns=['Category', 'Year', 'Value_1', 'Value_2'])
    
    df1 = pd.DataFrame(np.array([["D", 2021, 200, 400], 
                                 ["D", 2020, 600, 300],
                                 ["B", 2021, 500, 250], 
                                 ["B", 2020,  350, 432],
                                 ["C", 2022,  250, 532],
                                 ["C", 2022,  150, 232],]),
                       columns=['Category', 'Year', 'Value_1', 'Value_2'])
    with pd.ExcelWriter('test_output.xlsx') as writer:
        df.to_excel(writer, sheet_name='A')        
        df1.to_excel(writer, sheet_name='C') 
Green Finance
  • 195
  • 12
  • You aren't providing enough information for anyone to answer this. How and where is JupyterLab running? Is it installed on your local machine? Is it on a remote machine? Is it actually JupyterLab running as a JupyterLite / what kernel? Is it via a JupyterHub? There's a lot of ways to run JupyterLab. The most consistent route is to run your code and then when you see result in the file navigation pane on the left (usually), right click on the file listed there and choose 'Save As...' & then save to your local directory where you want it. You can also code making a download link for the users. – Wayne Apr 28 '23 at 16:49
  • *I have tried using the "download_path = os.path.expanduser("~") + "/Downloads/"" optio but this saves it to the static folder* What folder is "the static folder"? Why is that a problem? – topsail Apr 28 '23 at 17:31

0 Answers0