0

I would like to make a dropdown menu that shows each column name from the dataset, and the user can choose a column to visualize the data. With Python this code is:

for i in df.columns:
    plt.figure(figsize = (10,6))
    plt.title("Count vs "+i)
    sns.histplot(data = df, x = i, element = 'bars')

I have tried the following code, which does not account for each column name, nor does it output charts similar to the above code.

def f(x):
    return x

def f(age):
    df.loc[age].iplot(
                    xTitle='Year', 
                    yTitle='Count of {}'.format(age),
                    title='Count per Age'
                     )

interact(f, age=df.index)
  • 1
    `f` doesn't return anything after you overwrite it with the second `f` function. – BeRT2me Apr 22 '22 at 03:33
  • [This one using Plotly](https://stackoverflow.com/a/71709798/8508004) is similar. [This one](https://stackoverflow.com/q/71296687/8508004) is less simple. For non-Plotly options...the ['country-indicators' example](https://mybinder.org/v2/gh/binder-examples/voila/HEAD?urlpath=voila%2Frender%2Findex.ipynb) at [the Voila Gallery](https://voila-gallery.org/) might give you some ideas. You can see the notebook version of it by [clicking here](https://mybinder.org/v2/gh/binder-examples/voila/HEAD?urlpath=lab%2Ftree%2Findex.ipynb). – Wayne Apr 22 '22 at 03:53
  • Almost forgot to add, some other related examples, simpler than the country-indicators one, are available [here](https://github.com/fomightez/3Dscatter_plot-binder). You can work through them actively by clicking the `launch binder` badge there and then selecting '3D scatter plots customizable via widgets' and the two notebooks listed after that in available notebooks. – Wayne Apr 22 '22 at 16:47

0 Answers0