From 6f1e399503deb0bbec26e9a56b5766992fc4fe77 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 14 Dec 2018 15:48:05 -0500 Subject: [PATCH] add loc and iloc to subsetting (#23812) broaden subetting topic to include the other slicing/indexing methods --- guide/english/data-science-tools/pandas/index.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/guide/english/data-science-tools/pandas/index.md b/guide/english/data-science-tools/pandas/index.md index 41273443a1..cb327ead20 100644 --- a/guide/english/data-science-tools/pandas/index.md +++ b/guide/english/data-science-tools/pandas/index.md @@ -45,11 +45,16 @@ df.tail() ``` This will show the last 5 rows of the data frame. -## Subsetting: Getting a column by name +## Subsetting A data frame can be subset in many ways. One of the simplest is getting a single column. For instance, if the data frame `df` contains a column named `age`, we can extract it as follows: ```python ages=df["age"] ``` +Another option for subsetting a dataframe is using the loc and iloc methods. The difference between loc and iloc is that loc searches based on a label and iloc searches based on the integer value of a row or column. To perform the same indexing as the above example using loc: +```python +ages=df.loc["age"] +``` + #### More Information: 1. [pandas](http://pandas.pydata.org/)