Haseeb Sultan
Haseeb Sultan

Reputation: 103

Comparing column enteries with an array or a list

I have a dataframe , containing a column (User ID) containing enteries : 1,2,3 ... etc and I want to compare those enteries with a list/array and find out which numbers are missing ?

How do I achieve that? How do I compare that user_ID column with an Array (a)

enter image description here

Upvotes: 0

Views: 37

Answers (1)

Stefan B
Stefan B

Reputation: 1677

A bit of set-magic would do the trick if you're looking for which numbers are missing from a in your case:

a = range(1, 101)
# if values in DataFrame are stored as floats/ints
missing_from_range = set(a).difference(data1['user_iD'])

# if values in dataframe are stored as strings/objects
missing_from_range = set(a).difference(data1['user_iD'].astype(int))

Upvotes: 1

Related Questions