0

I generated a unique value based from a column but what I want to get as a result is the transmuted value from a different column. Here's the code for your reference:

x = [[123, "M"],
     [321, "F"],
     [456, "M"],
     [678, "F"],
     [654, "M"],
     [123, "M"],
     [678, "F"],
     [678, "F"],
    ]

x = pd.DataFrame(x, columns = ["ID", "GENDER"])

Getting the unique value

[in]: x["ID"].unique()
[out]: array([123, 321, 456, 678, 654], dtype=int64)

Expected Result:

[out]: ["M", "F", "M", "F", "M"]
Underoos
  • 4,708
  • 8
  • 42
  • 85
Maku
  • 1,476
  • 10
  • 21

1 Answers1

2

The ID is unique, so the gender also the same if the ID is identical. That means you have duplicates. So you can use:

x.drop_duplicates()
qinlong
  • 731
  • 8
  • 19