To subset a dataframe based on index value, you can use the .loc
accessor.
Here's an example:
main.py391 chars18 lines
In the code above, we first create a sample dataframe with a 'name', 'age', and 'salary' column. We then set the 'name' column as the index. To subset the dataframe based on index value, we use the .loc
accessor and pass in the range of index values we are interested in (in this case, 'Bob' to 'Dave'). Finally, we print the subset dataframe.
The output will be:
main.py104 chars6 lines
gistlibby LogSnag