# Is there a python code to perform the following task in python

Is there a way by which I can find how many people rated below 60% or how much percentage of people gave a rating of less than 60%.

This is the sample rating for the product. Where a 6 represents 60%. The data is currently stored in a pandas dataframe.

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

dataset['Z32'].describe() # gives me a output

count        24114.000000
mean         4.327445
std          2.086072
min          1.000000
25%          3.000000
50%          4.000000
75%          6.000000
max         10.000000

counts = dataset['Z32'].value_counts()
print(counts)

5     5831
4     3722
3     3384
6     2874
1     2836
2     2218
7     1451
8     1040
9      416
10     342
• put example data as text, not image. Dec 8, 2019 at 9:48
• I don't know what you have in dataset so I guess len(dataset[ datase['z32] < 6 ]) ? Or maybe even shorter sum(datase['z32] < 6) Dec 8, 2019 at 9:50
• dataset is a rating on the scale of 1 to 10 Dec 8, 2019 at 9:52

If dataset means pandas.DataFrame then you can use

dataset['rate'] < 6

to get dataset with values True/False which can sum because True is converted to 1 and False is converted to 0

count = sum(dataset['rate']<6)  # 17

If you get number of all rows in dataset len(dataset) then you can calculate percentage value

percent = count/len(dataset)   # 0.8 (80%)

Working example

import pandas as pd

dataset = pd.DataFrame({
'rate': [9, 6, 2, 2, 8, 5, 4, 4, 5, 4, 4, 2, 4, 5, 3, 5, 7, 3, 5, 4, 1]
})

count = sum(dataset['rate']<6)
percent = count/len(dataset)

print(count, percent, '{:.2%}'.format(percent))

Result

17 0.8095238095238095 80.95%