r/IPython • • 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 interact

Dataframe 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_res

but 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

3 comments sorted by

View all comments

Show parent comment

1

u/BWrqboi0 Sep 27 '19

Please share the whole updated code, something isn't right here.