Importing Dataset for demonstration
To explain the method a dataset has been created which contains data of points scored by 10 people in various games. The dataset is loaded into the Dataframe and visualized first. Ten people with unique player id(Pid) have played different games with different game id(game_id) and the points scored in each game are added as an entry to the table. Some of the player’s points are not recorded and thus NaN value appears in the table.
Note: To get the CSV file used, click here.
Python3
import pandas as pd df = pd.read_csv(r "__your file path__\example2.csv" ) print (df) |
Output:
We will select rows from Dataframe based on column value using:
- Boolean Indexing method
- Positional indexing method
- Using isin() method
- Using Numpy.where() method
- Comparison with other methods
How to select rows from a dataframe based on column values ?
Prerequisite: Pandas.Dataframes in Python
In this article, we will cover how we select rows from a DataFrame based on column values in Python.
The rows of a Dataframe can be selected based on conditions as we do use the SQL queries. The various methods to achieve this is explained in this article with examples.