Skip to content
Advertisement

Python find the unique values in a spesific column. 2d array

Good day.

If I have the following array:

JavaScript

How can I change the array to only show data from user pear? I want to collect all the values from column 1 of user pear. (12, 14)

Or alrternatively how can I find the values that are unique in colum 2, e.g. apples, pear and bannana. And then filter by pear to find the data only of pear. [12, “pear”, 24, 11], [14, “pear”, 17, 11]

What have I tried and vary forms of it:

uniqueRows = np.unique(array, axis=:,1)

This is what I can use to filter if I have the unique values.

JavaScript

Advertisement

Answer

Pandas Way

JavaScript

However instead of drop_duplicate you can use unique() but this way is faster.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement