1

As an example, I have a set of records in a 2D numpy.array and I would like to select all records where value in the 3rd column equal 10. Is there a way to do that apart from looping through the array and build a list of the selected records?

2 Answers 2

0

Here I have created a numpy array.

print(df)

o/p is: array([['A', 'car'],['B', 'bike'],['C', 'car'],['D', 'truck']], dtype=object)

Now to select all rows with car, you can just filter that value from the array

df[df == "car"]

o/p is: array(['car', 'car'], dtype=object)

If you want it to be converted to python list, wrap the statement in list, i.e

list(df[df == "car])

Sign up to request clarification or add additional context in comments.

1 Comment

Using your example, what I'm looking for is a filter that will return [['A', 'car'],['C', 'car']]
0

Once I knew of the 'filter' concept, I searched some more and found the answer I was looking for in this stackoverflow question.

So in the car example, the filter would be written as df[df[:,1] == 'car']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.