Python Forum
unique on 2 columns at the same time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unique on 2 columns at the same time
#1
Hi,

I'm looking for a way to get unique couple of data on 2 columns here as shown bellow; I had to look to numpy and Pandas, duf on internet, but I still looking for a goof way: any suggestion?
Thanks
Paul
import numpy as np

A = np.array([['A', 'x'],
              ['C', 'y'],
              ['B', 'z'],
              ['C', 'x'],
              ['C', 'y'],
              ['Z', 'z']])    

# Expected :
A_unique = np.array([['A', 'x'],
                     ['C', 'y'],
                     ['B', 'z'],
                     ['C', 'x'],
                     ['Z', 'z']])   
Reply
#2
import numpy as np
 
A = np.array([['A', 'x'],
              ['C', 'y'],
              ['B', 'z'],
              ['C', 'x'],
              ['C', 'y'],
              ['Z', 'z']])

print(np.unique(A, axis=0))
Output:
[['A' 'x'] ['B' 'z'] ['C' 'x'] ['C' 'y'] ['Z' 'z']]
Reply
#3
humm I used it. I guess i did a mistake
Thanks
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020