Optimizing counting number of occurrences of a given number in an array

But, wanting to use the Dataframes “trick”, I don’t see any alternatives.