OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Getting ONLY unique rows from a dataframe [duplicate]

  • Thread starter Thread starter datanerd
  • Start date Start date
D

datanerd

Guest
I'm trying to remove all rows that have any duplicates. I ONLY want the unique rows. I've tried the keep = False parameter for drop_duplicates() with `subset = [ORDER ID, ITEM CODE] , and its just not doing the right thing.

lets say my dataframe looks something like this

Code:
|ORDER ID | ITEM CODE |
123         XXX    
123         YYY
123         YYY
456         XXX
456         XXX
456         XXX
789         XXX
000         YYY

I want it to look like this:

Code:
|ORDER ID | ITEM CODE |
123         XXX    
789         XXX
000         YYY

As you can see the subset would be both the order ID and Item code columns and we would lose rows 2-6 ideally. (The actual dataset has a lot more columns.)
<p>I'm trying to remove all rows that have any duplicates. I ONLY want the unique rows. I've tried the <code>keep = False</code> parameter for <code>drop_duplicates()</code> with `subset = [ORDER ID, ITEM CODE] , and its just not doing the right thing.</p>
<p>lets say my dataframe looks something like this</p>
<pre><code>|ORDER ID | ITEM CODE |
123 XXX
123 YYY
123 YYY
456 XXX
456 XXX
456 XXX
789 XXX
000 YYY
</code></pre>
<p>I want it to look like this:</p>
<pre><code>|ORDER ID | ITEM CODE |
123 XXX
789 XXX
000 YYY
</code></pre>
<p>As you can see the subset would be both the order ID and Item code columns and we would lose rows 2-6 ideally. (The actual dataset has a lot more columns.)</p>
 

Latest posts

Top