1

I have the following dataset.

  1. 1 2
  2. 2 5
  3. 3 4
  4. 4 7
  5. 6 8
  6. 7 6

My aim is to have a count of numbers in column 2 which are less than or equal 6. The numbers in column 2 which are less than or equal to 6 are 2,4,5 and 6. So, i want the output to be 4 as 2,4,5 and 6 are all appearing once, so total appearance count=4.

My approach has been:

import numpy as np
data=np.loadtxt('/Users/Hrihaan/Desktop/A.txt')
x=data[:,1]
Count=list(x.flatten()).count(6)  #it only counts the number of times 6 appears in the list.

Any suggestion on how to manipulate the code to get a count for numbers equal or less than 6 would mean a lot.

Hrihaan
  • 275
  • 5
  • 21

1 Answers1

3

try this:

count = len([i for i in x if i <= 6])
nat5142
  • 485
  • 9
  • 21