Reputation: 20101
I have a dataframe with time index and some columns, similar to
dt, col1, col2, col3
12, 0.9, 0.3, 0.1
13, 0.9, 0.3, 0.2
14, 2.9, 0.4, 0.1
15, 0.1, 0.3, 0.7
and I can create a Holoviews Curve wihtout a problem for each column. Is it possible to generate a graph with a drop down menu selecting between [col1, col2, col3]?
Upvotes: 0
Views: 1008
Reputation: 4080
HoloViews is primarily set up to plot so called "tidy" or long dataframes easily, so to take full advantage of the power of HoloViews you will want to convert the data to that format. The pd.melt
function is very useful to convert "wide" to tidy data. Based on your example you could do something like this
df = pd.DataFrame({'dt': range(10), 'col1': np.random.rand(10),
'col2': np.random.rand(10), 'col3': np.random.rand(10)})
tidy_df = pd.melt(df, id_vars='dt', var_name='column', value_name='value')
ds = hv.Dataset(tidy_df)
ds.to(hv.Curve, 'dt', 'value', 'column')
Alternatively you can also manually create a HoloMap manually:
df = pd.DataFrame({'dt': range(10), 'col1': np.random.rand(10),
'col2': np.random.rand(10), 'col3': np.random.rand(10)})
hv.HoloMap({col: hv.Curve(df, 'dt', col) for col in ['col1', 'col2', 'col3']},
kdims='Column')
Having said all this, your use case is a very common one and the next release of HoloViews will include ways of making this kind of thing much easier, so look out for a user guide about working with pandas DataFrames once that lands.
Upvotes: 1