Skip to content

Instantly share code, notes, and snippets.

Last active March 17, 2022 18:50
  • Star 19 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save TomAugspurger/6e052140eaa5fdb6e8c0 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link

gepcel commented Dec 28, 2014

Wonderful notebook! Helps me know R better. There might be something that will help others know pandas better.

Anyway, as in In[8], flights.iloc[:9] is fine. But wouldn't flights.loc[:10] be more equivalent?

And In[12]:

# select(flights, year:day) 

# No real equivalent here. Although I think this is OK.
# Typically I'll have the columns I want stored in a list
# somewhere, which can be passed right into __getitem__ ([]).

I'm only guessing what the R code does, but how about flights.loc[:, 'year':'day'] ? And if there's a list of columns to get, named columns for example, I think flights[columns] will do, other than __getitem__ ([]).

And In[13]:

# select(flights, -(year:day)) 

If I'm guessing right, flights.loc[:, ~flight.columns.isin(a.loc[:, 'year':'day'])] might do. But it's a little bit tedious and less elegant than R.

Again, a very helpful notebook.

Copy link

pwwang commented Mar 17, 2022

For those who are struggling to translate your R code into python, you might want to take a look at this package:

which reimages pandas APIs and aligns them with tidyverse's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment