-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Making Pandas dataframe slicing syntax match R dataframe syntax. #35659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jgbradley1 this is impossible to actually do (as would break the world), nor likely wanted.
We already have
|
@jreback Thanks for the quick follow-up. I'm not sure what you mean. If you're referring to the syntax, I wrote a very basic
From that example, it wouldn't be too difficult to extend and allow the mixed used of integer-based and label-based indexing all within the bracket notation and thus not forcing users to pick between Thanks for linking to the other issue. Seems like the discussion has been going for a long time but I did want to post a working example all the same to show it's not impossible. |
@jgbradley1 its certainly possible and we used to have the It is impossible to change the default as something would likey break the world w/o an easy deprecation. Extensions to |
I imagine the following request is popular enough that it has probably been asked before. I just couldn't find it. Feel free to close if the discussion has already occurred.
Consider the following R example:
The equivalent Pandas syntax would be:
Now when trying to slice a R dataframe, the syntax allows direct access with the brackets operator:
The pandas equivalent would be:
Disregarding the 0-index vs 1-index between the languages, I would like to propose adding a new slicing operation to the Pandas dataframe
getitem()
that overloads the brackets operator and matches the behavior of R-style syntax. It would allow for cleaner and less-verbose code (especially when chaining multiple slice operations).API breaking implications
The API change would be a positive addition. No removal of current slicing operations (
iloc
,loc
, etc.)Additional context
The following slicing examples will error out in Pandas whereas it would be valid slicing in R:
Note that calling
iloc
with the above commands would all succeed. What I'm suggesting is that the logic foriloc
be copied/moved into Pandas dataframe__getitem__()
function.The text was updated successfully, but these errors were encountered: