The pandas conditional search returns a list of methods

  • 2021-01-14 06:14:57
  • OfStack

One of the common things in pandas is to search for specific conditions, so here is the use of pandas search method, the case used pandas is anaconda, you can download any anaconda installation will be included.

First import the package


import pandas as pd
import os

Then you need to build 1 csv file to save the file. For example, if we have a file named test.csv, the file has three column headers, id, name, address, we want to know the name of a person id and address can be written


test_csv = pd.read_csv('/test.csv', encoding='gb2312')#  If you have Chinese, please gb2312
info_Joan = test_csv[test_csv['name']='Join] #  So we have Joan the id As well as address  information 

Or is it


info_Joan =test_csv[test_csv['name']isin(['Join'])]

The rest is what you want. Such as getting values or composing lists


[list(x) for x in info_Joan['id'].values]

Related articles: