.interactive dataframe slice selection by row index or position not possible
See original GitHub issueIs your feature request related to a problem? Please describe.
I was in the assumption that the .interactive interface for dataframes should mimic the interface of pandas. Yet not everything seems to work.
Given the code
import hvplot.pandas
import panel.widgets as pnw
from bokeh.sampledata import airports
df = airports.data
dfi = df.interactive()
p = pnw.IntSlider(start=10, end=40)
dfi[5:p]
I would like to see a slider and a dynamic dataframe representation showing index 5…p-1 (that dataframe has an integer index). Instead I get a static output without slider. I can make one in another cell, but when I move it, the dataframe output does not update. I need to execute the cell manually again to get the update.
This here doesn’t work at all and gives an InvalidIndexError
dfi.loc[5:p,:]
# InvalidIndexError: IntSlider(end=40, start=10, value=10)
Those here give no slider and don’t update when I create a slider in another cell:
dfi.loc[:p]
dfi.iloc[5:p]
dfi.iloc[slice(5,p)]
dfi.values[5:p]
This here gives a type error
dfi.loc[dfi.index[5:p]]
# TypeError: slice indices must be integers or None or have an __index__ method
A current workaround for dfi.loc[5:p,:]
is:
dfi[(dfi.index>=5) & (dfi.index<p)]
For dfi.iloc[5:p]
I have no reasonable workaround (except for resetting the index, selecting via above method and setting it again).
Neither dfi.values[5:p]
nor dfi.loc[dfi.index[5:p]]
as a workaround work, and I don’t know what else to try.
Literally the first example in the interactive tutorial (https://hvplot.holoviz.org/user_guide/Interactive.html) has indexing by position in an xarray with .isel
, which I think i have tried and it works. So it is surprising to me that there is no mechanism to select a positional range in dataframes.
Issue Analytics
- State:
- Created a year ago
- Comments:20 (5 by maintainers)
Top GitHub Comments
I got it to work with slices, and will submit PRs in holoviews and hvplot today.
https://user-images.githubusercontent.com/19758978/177975269-75bdf24f-7fee-4f08-a17d-906b0a5cf9d6.mp4
Great work @JanHomann! I will look into what is possible to add to interactive.