Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find which values are in one pandas series but not another?

Tags:

python

pandas

Given two pandas series, how can I find which elements are in 1 but not another? All elements within each series are unique.

For example, consider the following code :

a = pd.Series([1,2,3,4])
b = pd.Series([3,2,4])

How would I be able to determine which elements are in Series 'a' but not in Series 'b'? In this example, the output would be [1].

like image 362
Evan Avatar asked Oct 20 '25 01:10

Evan


2 Answers

Do you mean what are the unique values? For example if you have

a = pd.series([1,1,1,2])
b = pd.series([1,3]) 

The output should be [1] or [1,1,1] ?

If [1] you can use:

set(a) - set(b)
like image 172
theletz Avatar answered Oct 21 '25 16:10

theletz


set(a) - set(b)

guess this should help

like image 35
Bhosale Shrikant Avatar answered Oct 21 '25 17:10

Bhosale Shrikant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!