Jul-15-2019, 04:58 PM
(This post was last modified: Jul-15-2019, 04:58 PM by ptaylor520.)
I managed to get a workaround but I don't think this this is the best practice:
26.89
28.29
32.8
12.01
Any better ways of writing this query?
import pandas as pd tsjune = pd.read_csv("/Users/phil/Documents/datacsv/tsj.csv", delimiter = ',') one = tsjune[(tsjune.Difference >= 0) & (tsjune.Difference <=1)] two = tsjune[(tsjune.Difference > 1) & (tsjune.Difference <=3)] three = tsjune[(tsjune.Difference > 3) & (tsjune.Difference <30)] four = tsjune[tsjune.Difference >= 30] onecount = one.count() twocount = two.count() threecount = three.count() fourcount = four.count() total = onecount + twocount + threecount + fourcount onepercentage = round(onecount/total*100, 2) twopercentage = round(twocount/total*100, 2) threepercentage = round(threecount/total*100, 2) fourpercentage = round(fourcount/total*100, 2) print(onepercentage['Difference']) print(twopercentage['Difference']) print(threepercentage['Difference']) print(fourpercentage['Difference'])Which gives me a percentage output of:
26.89
28.29
32.8
12.01
Any better ways of writing this query?