0

I'm trying to recreate the first panel.interact example in the Holoviz tutorial using a Pandas dataframe instead of a Dask dataframe. I get the slider, but the pandas dataframe row does not show.

See the original example at: http://holoviz.org/tutorial/Building_Panels.html

I've tried using Dask as in the Holoviz example. Dask rows print out just fine, but it demonstrates that panel seem to treat Dask dataframe rows differently for printing than Pandas dataframe rows. Here's my minimal code:

import pandas as pd
import panel
l1 = ['a','b','c','d','a','b']
l2 = [1,2,3,4,5,6]
df = pd.DataFrame({'cat':l1,'val':l2})
def select_row(rowno=0):
    row = df.loc[rowno]
    return row
panel.extension()
panel.extension('katex')
panel.interact(select_row, rowno=(0, 5))

I've included a line with the katex extension, because without it, I get a warning that it is needed. Without it, I don't even get the slider.

I can call the select_row(rowno=0) function separately in a Jupyter cell and get a nice printout of the row, so it appears the function is working as it should.

Any help in getting this to work would be most appreciated. Thanks.

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
tpegbert
  • 176
  • 1
  • 6

1 Answers1

0

Got a solution. With Pandas, loc[rowno:rowno] returns a pandas.core.frame.DataFrame object of length 1 which works fine with panel while loc[rowno] returns a pandas.core.series.Series object which does not work so well. Thus modifying the select_row() function like this makes it all work:

def select_row(rowno=0):
    row = df.loc[rowno:rowno]
    return row

Still not sure, however, why panel will print out the Dataframe object and not the Series object.

Note: if you use iloc, then you use add +1, i.e., df.iloc[rowno:rowno+1].

tpegbert
  • 176
  • 1
  • 6