Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages, and makes importing and analyzing data much easier.
The most important thing in Data Analysis is comparing values and selecting data accordingly. The “==” operator works for multiple values in a Pandas Data frame too. Following two examples will show how to compare and select data from a Pandas Data frame.
To download the CSV file used, Click Here.
Example #1: Comparing Data
In the following example, a data frame is made from a csv file. In the Gender Column, there are only 3 types of values (“Male”, “Female” or NaN). Every row of Gender column is compared to “Male” and a boolean series is returned after that.
As show in the output image, for Gender= “Male”, the value in New Column is True and for “Female” and NaN values it is False.
Example #2: Selecting Data
In the following example, the boolean series is passed to the data and only Rows having Gender=”Male” are returned.
As shown in the output image, Data frame having Gender=”Male” is returned.
Note: For NaN values, the boolean value is False.
- Limited rows selection with given column in Pandas | Python
- Data profiling in Pandas using Python
- Python | Pandas Series.data
- Data Manipulattion in Python using Pandas
- Python | Data analysis using Pandas
- Python | Pandas Index.data
- Get the data type of column in Pandas - Python
- Python | Filtering data with Pandas .query() method
- How to Filter and save the data as new files in Excel with Python Pandas?
- Python | Pandas Series.astype() to convert Data type of series
- Python Object Comparison : "is" vs "=="
- Python | Consecutive String Comparison
- Python | Excel File Comparison
- Chaining comparison operators in Python
- Comparison of Python with Other Programming Languages
- Comparison between Lists and Array in Python
- Python | Selective value selection in list of tuples
- Pandas Built-in Data Visualization | ML
- Using csv module to read the data in Pandas
- Indexing and Selecting Data with Pandas
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.