rl30ml
rl30ml7mo ago

DataFrames and reactivity

How would you recommend handling reactivity within a pandas dataframe and between pandas dataframes? For example, I have a dataframe with three time series, each in a column and the third column is the product of the first two columns (multiplicand and multiplier). If I change an element of the multiplier column, I would like the product column to be updated. If instead of one dataframe, I had three dataframes, one for each column, and I changed the multiplier dataframe, I would like the product dataframe to be updated. Thank you.
5 Replies
Akshay
Akshay7mo ago
You'd want to declare the data before creating the dataframes, that way when the data changes the dataframes change.
Akshay
Akshay7mo ago
Like here's one example for your second ask (three dataframes), using UI elements just to make the example tangible: Live notebook link: https://marimo.app/l/f9jhok
No description
rl30ml
rl30mlOP7mo ago
I am wondering if there is a more efficient way. This way the entire column of multipliers has to be created each time there is a change. I was thinking of doing Monte Carlo simulations where the multiplier is a random variable, so small penalties could grow.
Akshay
Akshay7mo ago
I wonder if you need reactivity here? Why not just do this in a function? If you want to show outputs along the way, you can use mo.output.append and mo.output.replace: https://docs.marimo.io/api/outputs.html
rl30ml
rl30mlOP7mo ago
Yes, functions would be clear and less error-prone than spreadsheets, where it is easy to accidentally skip a row or column. I will think about that. Because spreadsheet formulas link cells and only recalculate changed cells, they might be faster than reactivity/functions which recalculate ranges of cells, even if there is only a dependency relationship between two cells.