Skip to content
Advertisement

Compare two pandas series and remove duplicates

I have two series:

ser1 = pd.Series([1,2,3,4,5])
ser2 = pd.Series([4,5,6,7,8])

I want to compare ser1 and ser2 and then remove the duplicates and put the result into ser1 to have something like this:

>>> ser1
    out = 1 2 3

I tried pd.concat but this gave me the combination of the two series without removing the duplicates.

Advertisement

Answer

(set(ser1).difference(ser2))
{1, 2, 3}
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement