Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:23:37+00:00 2026-06-11T21:23:37+00:00

I have a data set that may contain duplicates. In order to find the

  • 0

I have a data set that may contain duplicates. In order to find the duplicates in the dataset I put the indices into a numpy structured array, sort the array, create another array from the unique values and then compare the lengths of the two arrays:

data = np.zeros(t_len, dtype={'names':['date', 'symbol'], 'formats':['i8', 'S16']})
data[:] = [(x['date'], x['symbol']) for x in tbl.iterrows()]
data.sort(order=['date', 'symbol'])
data2 = np.unique(data)
duplicates = False

if len(data) != len(data2):
    duplicates = True
    print "There are duplicates"

if not duplicates:
    print "No duplicates found"

Now, what I would really like to do is determine the indices that contain the duplicates. For example, if I had a dataset that contained:

array([12322323,'IBM'], [12322323,'IBM'], [12322323,'MSFT'], [12322323,'IBM'])

I would like to know see an array with array([12322323,’IBM’])

I’ve looked into using unique and difference functions, but those don’t seem to do the job.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:23:39+00:00Added an answer on June 11, 2026 at 9:23 pm

    For simplicity, I’ll just use an array of integers, x, as the input:

    >>> x = np.array([20, 10, 30, 10, 60, 30, 10])
    

    With numpy version 1.9.0 or later, we can use np.unique to get the unique elements, with the argument return_counts=True so that the number of occurrences of each unique element is also returned

    >>> u, counts = np.unique(x, return_counts=True)
    


    For older versions of numpy, one can use np.unique with the argument return_inverse=True to also get the array that shows how to recreate x from the array of unique elements:

    >>> u, inv = np.unique(x, return_inverse=True)
    >>> u
    array([10, 20, 30, 60])
    >>> inv
    array([1, 0, 2, 0, 3, 2, 0])
    

    Now use bincount to count the number of occurrences of each element:

    >>> counts = np.bincount(inv)
    >>> counts
    array([3, 1, 2, 1])
    

    So now we have counts, which tells us how many times each element occurs in the array. We can pull out the elements that have duplicates as follows:

    >>> dups = u[counts > 1]
    >>> dups
    array([10, 30])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of data that is structured like this: ItemA.GroupA ItemB.GroupA ItemC.GroupB
I have a data set that should contain 14 columns, but when I read
I have three variables that may or may not contain data. let's call them
I have a set of rows that contain duplicate entries because the data originates
I have a dataset of about 3000 rows in openoffice, each set MAY contain
I have some columns that may contain data that is if the user wants
Imagine you have a large dataset that may or may not be filtered by
I have a data set that resembles this: id product_id size color price created_date
I have a data set that is around 700 rows with eight columns of
I have a data set that that I would like to call in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.