Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to extract all first value in a column from other column

I got a table like that :

house
house
house
dog
dog
dog

And I would like to have only first occurence of each different words. So I would like to have a column like that

house     house
house
house
dog       dog
dog
dog

thanks for reading me

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading