Filter by conditions inside 14.pandas

Screening is used very frequently in daily work functions previously introduced loc and screening methods iloc now continue to introduce some method of screening.

8612260-cc0bfd1e33b3a1a7.png
image

In>, <, ==,> =, <= be selected ( "equals" must be a '==', if the '=' the size is not determined):

8612260-1c73393e971809ab.png
image
8612260-3158f8e1b4e1ec62.png
image

Using & (and) and | (or) with each condition must be enclosed in parentheses.

Select multiple rows must be two brackets, wherein the inner side of the square brackets is representative of a list:

8612260-71086ec8bbf1f977.png
image
8612260-15221779c8d0eaa2.png
image

If you want to select a column to multiple values or strings to use .isin (), we modified a bit df ( ISIN () brackets should be a List ):

8612260-a28d4eccfe2d78e4.png
image
8612260-494017623f7290b9.png
image

Usually the most used screening should be screened fuzzy string, used in an SQL statement is like, where the pandas we can use .str.contains () to achieve.

8612260-b6b789cfa3da290a.png
image
8612260-60e7a490a45d80ff.png
image

You can also use '|' to be screened multiple conditions:

8612260-0c07d4d0364858d9.png
image
8612260-c6f4fd6f607886fb.png
image
8612260-992f22f786ee221f.png
image

Note that, the '|' is in quotation marks, instead of the two strings are in quotes. '&' Can not be used here.

If the middle of .str not the case, an error occurs, it is suggesting that 'Series' array is not 'contains' function.

8612260-4af8e23b89c4ab2c.png
image

In fact, the role is .str 'Series' is converted into Strings similar structure, then you can use the function contains.

Author: Exploring the beauty of data
link: https://www.jianshu.com/p/805f20ac6e06
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.

Guess you like

Origin blog.csdn.net/weixin_34119545/article/details/90941825