r/IPython • u/Gromadusi77 • Sep 27 '19
Merging Dynamic Dataframes
I'm looking for help to add two dynamically generated (--> ipywidgets intslider) dataframes.
import pandas as pd
from ipywidgets import interactDataframe 1:
@interact(x=(0,1000,10))
def df_draw_one(x):
data = {"A":[1,2,3,4,5]}
df_one = pd.DataFrame(data)
df_one['B'] = df_one['A']*x
print(df_one)Dataframe 2
@interact(x=(0,1000,10))
def df_draw_two(x):
data = {"A":[6,7,8,9,10]}
df_two = pd.DataFrame(data)
df_two['B'] = df_two['A']*x
print(df_two)Dataframe result:
df_res = df_one+df_two
df_resbut get:
---> NameError: name 'df_one' is not defined
instead, i'd like df_res to update synchronously with any of above sliders.
I assume there's a lot missing, but can't find anything that points me to the right path.
1
Upvotes
View all comments
Show parent comment
1
u/Gromadusi77 Sep 27 '19
Thanks
adding df's works fine, as long as the series are identical.
i tested returning the df's, but the return types are of
<class 'function'>, not dataframes as expected