0

I got a table like this:

house
house
house
dog
dog
dog

And I would like to have only first occurrence of each different words. So I would like to have a column like this:

house     house
house
house
dog       dog
dog
dog
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Pierre
  • 41
  • 5

1 Answers1

2

If it is a dataframe, you can use:

df.column_name.unique()

if it is a numpy array:

np.unique(array)

If it is a list:

unique = list(set(data))

If you don't have the full data and it depends on anything else, you can use a function like:

   # initialize a null list
   unique_list = []
 
    # traverse for all elements
   for x in data: # read the data 
         # check if exists in unique_list or not
       if x not in unique_list:
           unique_list.append(x)
Sadcow
  • 680
  • 5
  • 13