add loc and iloc to subsetting (#23812)
broaden subetting topic to include the other slicing/indexing methods
This commit is contained in:
@ -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/)
|
||||
|
Reference in New Issue
Block a user