In this article let’s discuss how to search data frame for a given specific value using pandas.
- where() -is used to check a data frame for one or more condition and return the result accordingly. By default, The rows not satisfying the condition are filled with NaN value.
- dropna() -This method allows the user to analyze and drop Rows/Columns with Null values. In this article it is used to deal with the cases where the rows that will have value as NaN because they will not satisfy a certain condition.
- Import modules
- Create data
- Traverse through the column looking for a specific value
- If matched, select
There is a basic difference between selecting a specific values and selecting rows that have a specific value. For the later case the indices to be retrieved has to be stored in a list. Implementation of both cases is included in this article:
Data frame in use:
Example 1: Select tuple containing salary as 200
Example 2: Search for people having salary of 100 and store the output in a dataframe again.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.