question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.interactive dataframe slice selection by row index or position not possible

See original GitHub issue

Is 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:open
  • Created a year ago
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
Hoxbrocommented, Jul 8, 2022

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

2reactions
Hoxbrocommented, Jul 11, 2022

Great work @JanHomann! I will look into what is possible to add to interactive.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indexing and selecting data — pandas 1.5.2 documentation
This use is not an integer position along the index.). A list or array of labels ['a', 'b', 'c'] . ... With DataFrame,...
Read more >
Indexing and Selecting in Pandas - slicing - wrighters.io
In a DataFrame , slicing with [] will slice on the rows. If you remember back to the last post, selection on a...
Read more >
Indexing, Slicing and Subsetting DataFrames in Python
Manipulate and extract data using column headings and index locations. Employ slicing to select sets of data from a DataFrame.
Read more >
Selecting Subsets of Data in Pandas: Part 1
Sometimes the index is referred to as the row labels. ... It is possible to 'slice' the rows of a DataFrame with .loc...
Read more >
Pandas iloc and loc – quickly select data in DataFrames
The iloc, loc and ix indexers for Python Pandas select rows and columns from ... row with index value 487) is not equal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found