Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the conditional selection of rows by Pandas

Shulou Source: shulou.com Published: 2022-06-01 06:17:10 10月02日 Update

This article will explain in detail how to choose the conditions for Pandas to achieve the line. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

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.

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

Tags: Conditions selections data articles single more good practical simple important necessary content multiple customers skills parentheses income articles methods steps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Xiaomi Redmi Shulou Tech Info MySQL