0
votes

I am loading huge volume of data using xlwings UDF through pandas dataframe into Excel.

@xw.func
def load_csv(csvfile):
    
    import pandas as pd
    df = pd.read_csv(csvfile)
    
    app = xw.apps.active
    wb = app.books.active 
    
    cellrange = wb.app.selection
    rownum=cellrange.row
    colnum=cellrange.column
    
    xw.Range((rownum,colnum)).options(pd.DataFrame, header=1, index=True, expand='table').value = df

From the same excel file, I want to work on the dataframe for further processing (using someother UDF). Since I am using UDF, if I want to access the dataframe again I may need to refill the dataframe from source file again which takes enormous time and energy. I want somehow to retain the dataframe in python memory. Is there any way to do it? I thought of using jupyter since it retains the dataframe cell after cell. But I am stuck how to do it using xlwings UDFs? Is there anyway to work on jupyter notebook side by side with excel (like how pyxl does)?

I tried using nbconvert but even here I don't think I can retain the dataframe in memory. Please guide. Thank you!