Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the conditional selection of ​ rows in Pandas

Shulou Source: shulou.com Published: 2022-06-01 05:28:31 11月06日 Update

This article mainly introduces how to achieve line condition selection in Pandas, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Conditional selection of rows

First of all, data exploration is a necessary step. Pandas provides a quick and simple method for all kinds of analysis. One of the most important techniques is to select rows or filter data based on criteria.

The conditional selection of rows can be based on a single condition or multiple conditions in a single statement separated by logical operators.

For example, I use a dataset about loan forecasts.

We will select a row of clients who have not yet graduated and earn less than £5400. Let's see what we can do.

Video: https://youtu.be/hc4or_RF5M8

Import pandas as pddata = pd.read_csv ('.. / Data/loan_train.csv') data.head () data2 = data.loc [(data ['Education'] = =' Not Graduate') & (data ['ApplicantIncome'])

Tags: Conditions selection article data single simple important necessary value interest at the same time multiple customers skills parentheses income methods more friends steps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info NVidia macOS Apple