CermakM / jupyter-datatables

Jupyter Notebook extension leveraging pandas DataFrames by integrating DataTables and ChartJS.
MIT License
238 stars 27 forks source link

Integration with ipywidgets #24

Open parallelko opened 4 years ago

parallelko commented 4 years ago

Is your feature request related to a problem? Please describe. I am dynamically changing DataFrame with function in ipywidgets, and i really loved your datatables. But it could't work together. Is it possible to do something that it could work together?

CermakM commented 4 years ago

Hello @parallelko, please provide a reproducible example or the whole notebook so that I could look into the issue.

Cheers, M

parallelko commented 4 years ago

Here is just simple example:

import warnings
warnings.filterwarnings('ignore')
import pandas as pd
from ipywidgets import interact
from jupyter_datatables import init_datatables_mode
init_datatables_mode() #jupyter_datatables improvements

d = {'department': [1, 2, 1, 2, 1, 2], 'name': ['Anton', 'Bob', 'Alice', 'Ivan', 'Jack', 'Jess'], 'Salary': [1000, 900, 2000, 1500, 800, 1100]}
df = pd.DataFrame(data=d)

def foo(DEP):
    showDF = df[(df['department'] == DEP)]
    num = showDF.sum(axis = 0, skipna = True)['Salary']
    showDF['RATIO'] = round(showDF['Salary']/num*100,1)
    return showDF.sort_values(by=['Salary'],ascending = False)

interact(foo,
         DEP = list(df['department'].unique()),
         );
CermakM commented 4 years ago

Hello! Ah, I can see the problem now, you want the data tables to actually reflect the dynamic changes. Gotcha! This is pretty interesting and I'll see what I can do.

Stay tuned.

Cheers, Marek