使用Series.isin()
即可,例:
检查['a', 'b', 'c', 'd', 'e', 'f']
的每一个元素是否在['a', 'b', 'bc', 'd', 'e']
中
import pandas as pd
series = pd.Series(['a', 'b', 'c', 'd', 'e', 'f'])
union_series = series[series.isin(['a', 'b', 'bc', 'd', 'e'])] # 取交集
print(union_series)