This notebook is a part of Pandas – Tips and Tricks mini-series, focusing on different aspects of pandas library in Python. In the below examples we will be looking at selecting the data by using .loc and .iloc methods. The notebook is also available on GitHub.
.loc: is primarily label based indexing.
.iloc: is primarily integer position based indexing.
Previous blog posts on the topic: Data import with Python, using pandas DataFrame – Part 1
Let’s start by importing pandas and loading the data:
# Loading the library import pandas as pd # I am using the data from WHO as an example df = pd.read_csv('Data/SuicBoth.csv') # Checking the DataFrame shape print(df.shape) # Checking the imported data df.head()