pandas中经常会需要对某列做一些筛选,比如筛选某列里的不包含某些值的行,类似sql里的in和not in功能,那么怎么实现呢。
import pandas as pd
columns = ['name','country']
index = [1,2,3,4]
row1 = ['a','China']
row2 = ['b','UK']
row3 = ['c','USA']
row4 = ['d','HK']
df = pd.DataFrame([row1,row2,row3,row4],
index=index,
columns=columns)
df
chinese = ['China','HK']
那么想查看数据中是chines的,
df[df.country.isin(chinese)]
查看数据中不是chines的,
怎么样,是不是很简单呢,你学会了么