DataFrame.loc does not work with list of indices
See original GitHub issueIf i = [3, 5, 1]
and df
is a pandas data frame this returns the numbered rows in the defined order: df.loc[i]
.
This is the expected behavior for dask.dataframe.DataFrame
but if df
is such an object then df.loc[i]
does not work. Note that you can give it a slice: df.loc[3:6]
for example.
On a side note, although using numbers in the example above, loc
is for labels and as such we could expect partitions made of indices (or multindices) of strings, datetimes, and other objects…
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Select Pandas rows based on list index - python
Use .iloc for integer based indexing and .loc for label based indexing. ... This will not work if the indexes in your dataframe...
Read more >pandas.DataFrame.loc — pandas 1.5.2 documentation
pandas.DataFrame.loc# ... Access a group of rows and columns by label(s) or a boolean array. .loc[] is primarily label based, but may also...
Read more >Pandas Select Rows Based on List Index
You can select rows from a list of Index in pandas DataFrame either using DataFrame.iloc[], DataFrame.loc]. iloc[] takes row indexes as a list....
Read more >A Python Beginner's Look at .loc. As ...
My first tip is that .loc is not a dataframe method; using () instead of ... You can also pass lists with row...
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 DataFrames. Simple guide to find data by position, label...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What about this one for larger lists?
ddf.map_partitions(lambda x: x[x.index.isin(L)])
I’m a little late to the party, but as of now, this is is an effective solution: