Skip to content

DOC: show users how to emulate R c function with iloc slicing and r_ #6499

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

Merged
merged 1 commit into from
Feb 27, 2014
Merged

DOC: show users how to emulate R c function with iloc slicing and r_ #6499

merged 1 commit into from
Feb 27, 2014

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Feb 27, 2014

No description provided.

@cpcloud cpcloud added the Docs label Feb 27, 2014
@cpcloud cpcloud self-assigned this Feb 27, 2014
@jorisvandenbossche
Copy link
Member

Nice comparison!
Just a remark, you didn't really give the pandas alternative for your first case (to access columns by name), so maybe add that? (df[, c("a", "c", "e")] -> df[["a", "c", "e"]])

@cpcloud
Copy link
Member Author

cpcloud commented Feb 27, 2014

@jorisvandenbossche Thanks! I'll add that.

columns = named + np.arange(len(named), 100).tolist()
df = DataFrame(np.random.randn(100, 100), columns=columns)

df.iloc[:, c(r_[:10], r_[24:30], 39, r_[49:100])]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think you can just do: df.iloc[:, r_[:10, 24:30, 39, 49:100]]?

Another alternative (without the somewhat strange r_ function) is the very basic usage of range (but somewhat longer):
df.iloc[:, range(10) + range(24, 30), range(49, 100)]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorisvandenbossche Awesome. I didn't know that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also just discovered it now :-) So certainly check if it is the same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, just checked it. Here's the SO question that inspired this addition to the docs.

@cpcloud
Copy link
Member Author

cpcloud commented Feb 27, 2014

@jorisvandenbossche Any more comments?

@jorisvandenbossche
Copy link
Member

Nope, thanks! Maybe just check tomorrow the rendered dev doc to see if everything looks good

jorisvandenbossche added a commit that referenced this pull request Feb 27, 2014
DOC: show users how to emulate R c function with iloc slicing and r_
@jorisvandenbossche jorisvandenbossche merged commit f94a8d5 into pandas-dev:master Feb 27, 2014
@cpcloud cpcloud deleted the r-slicing-with-c branch February 27, 2014 22:30
@jreback
Copy link
Contributor

jreback commented Feb 27, 2014

FYI the docs builds almost immediately after it's merged

http://pandas-docs.github.io/pandas-docs-travis/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants