Python group a range of percentage with increment and count the number of group












1















I have 3 groups of lists which are A1, A2, A3 as in group A, B1, B2, B3 in group B,
and C1, C2, C3 in group C.



a1 = ["ID_A1", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'C']]
a2 = ["ID_A2", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
a3 = ["ID_A3", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'G']]

b1 = ["ID_B1", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'T', 'C']]
b2 = ["ID_B2", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'A', 'C']]
b3 = ["ID_B3", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'G', 'C']]

c1 = ["ID_C1", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'A', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
c2 = ["ID_C2", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
c3 = ["ID_C3", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'G']]

data_set = [a1, a2, a3, b1, b2, b3, c1, c2, c3]


I have already compared their similarities with the codes below:



def compare(_from, _to):
similarity = 0
length = len(_from)
if len(_from) != len(_to):
raise Exception("Cannot be compared due to different length.")
for i in range(length):
if _from[i] == _to[i]:
similarity += 1
return similarity / length * 100

result = list()

for entry1 in data_set:
for entry2 in data_set:
percentage = compare(entry1[1], entry2[1])
print("Compare ", entry1[0], " to ", entry2[0], "Percentage :", round(percentage, 2))
result.append(round(percentage, 2))
print(result)


Instead of sorting all the similarities into a group according to their own value of similarities, I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range. I want it to have 0.1 increment because i have really big data but I cant insert here. When I loop the group (A compares from ID_A1 to ID_C3), every 95% to 96% will group into group A, and the number of group = 1, and when I loop the group (B compares from ID_A1 to ID_C3), every 95% to 96% will group into group B, and the number of group will be +1. The result that I want is showing the total number of groups in the range of 95% to 96%.



I would like to add something which is when in the range of 95.0% to 96.0%, IF there are 95.5% and 95.6%, how to group them as individual group?



The example output would be like:



"In the range of 95% to 96%, there is 1 group of 95.5% and 1 group of 95.6%"
"Total number of groups: ... "


PS: I need to use the number of groups to plot a graph










share|improve this question




















  • 1





    I can't seem to grasp what you're trying to ask... " I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range."

    – TrebuchetMS
    Nov 26 '18 at 14:54






  • 1





    the codes above will give you the results(similarities) in percentage (%), i would like to set a range which is 95% to 96% with an increment of 0.1, which is from 95.0, 95.1, 95.2 until 96.0%. From the results(similarities), if there are percentages from group A match the condition, then number of group +1. If no then continue to the next group

    – danny
    Nov 26 '18 at 15:19






  • 1





    @danny Could you add the actual desired output for your data to the question?

    – Joachim Isaksson
    Nov 26 '18 at 15:24











  • @JoachimIsaksson Done

    – danny
    Nov 26 '18 at 15:45











  • I think I get what you're trying to do. What is stopping you from doing it? When you try, what happens?

    – jez
    Nov 26 '18 at 16:11
















1















I have 3 groups of lists which are A1, A2, A3 as in group A, B1, B2, B3 in group B,
and C1, C2, C3 in group C.



a1 = ["ID_A1", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'C']]
a2 = ["ID_A2", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
a3 = ["ID_A3", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'G']]

b1 = ["ID_B1", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'T', 'C']]
b2 = ["ID_B2", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'A', 'C']]
b3 = ["ID_B3", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'G', 'C']]

c1 = ["ID_C1", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'A', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
c2 = ["ID_C2", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
c3 = ["ID_C3", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'G']]

data_set = [a1, a2, a3, b1, b2, b3, c1, c2, c3]


I have already compared their similarities with the codes below:



def compare(_from, _to):
similarity = 0
length = len(_from)
if len(_from) != len(_to):
raise Exception("Cannot be compared due to different length.")
for i in range(length):
if _from[i] == _to[i]:
similarity += 1
return similarity / length * 100

result = list()

for entry1 in data_set:
for entry2 in data_set:
percentage = compare(entry1[1], entry2[1])
print("Compare ", entry1[0], " to ", entry2[0], "Percentage :", round(percentage, 2))
result.append(round(percentage, 2))
print(result)


Instead of sorting all the similarities into a group according to their own value of similarities, I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range. I want it to have 0.1 increment because i have really big data but I cant insert here. When I loop the group (A compares from ID_A1 to ID_C3), every 95% to 96% will group into group A, and the number of group = 1, and when I loop the group (B compares from ID_A1 to ID_C3), every 95% to 96% will group into group B, and the number of group will be +1. The result that I want is showing the total number of groups in the range of 95% to 96%.



I would like to add something which is when in the range of 95.0% to 96.0%, IF there are 95.5% and 95.6%, how to group them as individual group?



The example output would be like:



"In the range of 95% to 96%, there is 1 group of 95.5% and 1 group of 95.6%"
"Total number of groups: ... "


PS: I need to use the number of groups to plot a graph










share|improve this question




















  • 1





    I can't seem to grasp what you're trying to ask... " I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range."

    – TrebuchetMS
    Nov 26 '18 at 14:54






  • 1





    the codes above will give you the results(similarities) in percentage (%), i would like to set a range which is 95% to 96% with an increment of 0.1, which is from 95.0, 95.1, 95.2 until 96.0%. From the results(similarities), if there are percentages from group A match the condition, then number of group +1. If no then continue to the next group

    – danny
    Nov 26 '18 at 15:19






  • 1





    @danny Could you add the actual desired output for your data to the question?

    – Joachim Isaksson
    Nov 26 '18 at 15:24











  • @JoachimIsaksson Done

    – danny
    Nov 26 '18 at 15:45











  • I think I get what you're trying to do. What is stopping you from doing it? When you try, what happens?

    – jez
    Nov 26 '18 at 16:11














1












1








1








I have 3 groups of lists which are A1, A2, A3 as in group A, B1, B2, B3 in group B,
and C1, C2, C3 in group C.



a1 = ["ID_A1", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'C']]
a2 = ["ID_A2", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
a3 = ["ID_A3", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'G']]

b1 = ["ID_B1", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'T', 'C']]
b2 = ["ID_B2", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'A', 'C']]
b3 = ["ID_B3", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'G', 'C']]

c1 = ["ID_C1", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'A', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
c2 = ["ID_C2", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
c3 = ["ID_C3", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'G']]

data_set = [a1, a2, a3, b1, b2, b3, c1, c2, c3]


I have already compared their similarities with the codes below:



def compare(_from, _to):
similarity = 0
length = len(_from)
if len(_from) != len(_to):
raise Exception("Cannot be compared due to different length.")
for i in range(length):
if _from[i] == _to[i]:
similarity += 1
return similarity / length * 100

result = list()

for entry1 in data_set:
for entry2 in data_set:
percentage = compare(entry1[1], entry2[1])
print("Compare ", entry1[0], " to ", entry2[0], "Percentage :", round(percentage, 2))
result.append(round(percentage, 2))
print(result)


Instead of sorting all the similarities into a group according to their own value of similarities, I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range. I want it to have 0.1 increment because i have really big data but I cant insert here. When I loop the group (A compares from ID_A1 to ID_C3), every 95% to 96% will group into group A, and the number of group = 1, and when I loop the group (B compares from ID_A1 to ID_C3), every 95% to 96% will group into group B, and the number of group will be +1. The result that I want is showing the total number of groups in the range of 95% to 96%.



I would like to add something which is when in the range of 95.0% to 96.0%, IF there are 95.5% and 95.6%, how to group them as individual group?



The example output would be like:



"In the range of 95% to 96%, there is 1 group of 95.5% and 1 group of 95.6%"
"Total number of groups: ... "


PS: I need to use the number of groups to plot a graph










share|improve this question
















I have 3 groups of lists which are A1, A2, A3 as in group A, B1, B2, B3 in group B,
and C1, C2, C3 in group C.



a1 = ["ID_A1", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'C']]
a2 = ["ID_A2", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
a3 = ["ID_A3", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'G']]

b1 = ["ID_B1", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'T', 'C']]
b2 = ["ID_B2", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'A', 'C']]
b3 = ["ID_B3", ['C', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'T', 'T', 'T', 'C', 'C', 'A', 'C', 'C', 'A', 'A', 'A', 'C', 'G', 'C']]

c1 = ["ID_C1", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'A', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
c2 = ["ID_C2", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'T']]
c3 = ["ID_C3", ['T', 'T', 'C', 'C', 'A', 'C', 'A', 'G', 'C', 'T', 'T', 'T', 'T', 'C', 'G', 'C', 'C', 'A', 'A', 'G', 'C', 'T', 'G']]

data_set = [a1, a2, a3, b1, b2, b3, c1, c2, c3]


I have already compared their similarities with the codes below:



def compare(_from, _to):
similarity = 0
length = len(_from)
if len(_from) != len(_to):
raise Exception("Cannot be compared due to different length.")
for i in range(length):
if _from[i] == _to[i]:
similarity += 1
return similarity / length * 100

result = list()

for entry1 in data_set:
for entry2 in data_set:
percentage = compare(entry1[1], entry2[1])
print("Compare ", entry1[0], " to ", entry2[0], "Percentage :", round(percentage, 2))
result.append(round(percentage, 2))
print(result)


Instead of sorting all the similarities into a group according to their own value of similarities, I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range. I want it to have 0.1 increment because i have really big data but I cant insert here. When I loop the group (A compares from ID_A1 to ID_C3), every 95% to 96% will group into group A, and the number of group = 1, and when I loop the group (B compares from ID_A1 to ID_C3), every 95% to 96% will group into group B, and the number of group will be +1. The result that I want is showing the total number of groups in the range of 95% to 96%.



I would like to add something which is when in the range of 95.0% to 96.0%, IF there are 95.5% and 95.6%, how to group them as individual group?



The example output would be like:



"In the range of 95% to 96%, there is 1 group of 95.5% and 1 group of 95.6%"
"Total number of groups: ... "


PS: I need to use the number of groups to plot a graph







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 16:13







danny

















asked Nov 26 '18 at 14:38









dannydanny

204




204








  • 1





    I can't seem to grasp what you're trying to ask... " I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range."

    – TrebuchetMS
    Nov 26 '18 at 14:54






  • 1





    the codes above will give you the results(similarities) in percentage (%), i would like to set a range which is 95% to 96% with an increment of 0.1, which is from 95.0, 95.1, 95.2 until 96.0%. From the results(similarities), if there are percentages from group A match the condition, then number of group +1. If no then continue to the next group

    – danny
    Nov 26 '18 at 15:19






  • 1





    @danny Could you add the actual desired output for your data to the question?

    – Joachim Isaksson
    Nov 26 '18 at 15:24











  • @JoachimIsaksson Done

    – danny
    Nov 26 '18 at 15:45











  • I think I get what you're trying to do. What is stopping you from doing it? When you try, what happens?

    – jez
    Nov 26 '18 at 16:11














  • 1





    I can't seem to grasp what you're trying to ask... " I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range."

    – TrebuchetMS
    Nov 26 '18 at 14:54






  • 1





    the codes above will give you the results(similarities) in percentage (%), i would like to set a range which is 95% to 96% with an increment of 0.1, which is from 95.0, 95.1, 95.2 until 96.0%. From the results(similarities), if there are percentages from group A match the condition, then number of group +1. If no then continue to the next group

    – danny
    Nov 26 '18 at 15:19






  • 1





    @danny Could you add the actual desired output for your data to the question?

    – Joachim Isaksson
    Nov 26 '18 at 15:24











  • @JoachimIsaksson Done

    – danny
    Nov 26 '18 at 15:45











  • I think I get what you're trying to do. What is stopping you from doing it? When you try, what happens?

    – jez
    Nov 26 '18 at 16:11








1




1





I can't seem to grasp what you're trying to ask... " I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range."

– TrebuchetMS
Nov 26 '18 at 14:54





I can't seem to grasp what you're trying to ask... " I want it to be grouped like in a range of 95% to 96% with an increment 0.1, depends on how user want to input the range."

– TrebuchetMS
Nov 26 '18 at 14:54




1




1





the codes above will give you the results(similarities) in percentage (%), i would like to set a range which is 95% to 96% with an increment of 0.1, which is from 95.0, 95.1, 95.2 until 96.0%. From the results(similarities), if there are percentages from group A match the condition, then number of group +1. If no then continue to the next group

– danny
Nov 26 '18 at 15:19





the codes above will give you the results(similarities) in percentage (%), i would like to set a range which is 95% to 96% with an increment of 0.1, which is from 95.0, 95.1, 95.2 until 96.0%. From the results(similarities), if there are percentages from group A match the condition, then number of group +1. If no then continue to the next group

– danny
Nov 26 '18 at 15:19




1




1





@danny Could you add the actual desired output for your data to the question?

– Joachim Isaksson
Nov 26 '18 at 15:24





@danny Could you add the actual desired output for your data to the question?

– Joachim Isaksson
Nov 26 '18 at 15:24













@JoachimIsaksson Done

– danny
Nov 26 '18 at 15:45





@JoachimIsaksson Done

– danny
Nov 26 '18 at 15:45













I think I get what you're trying to do. What is stopping you from doing it? When you try, what happens?

– jez
Nov 26 '18 at 16:11





I think I get what you're trying to do. What is stopping you from doing it? When you try, what happens?

– jez
Nov 26 '18 at 16:11












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53483438%2fpython-group-a-range-of-percentage-with-increment-and-count-the-number-of-group%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53483438%2fpython-group-a-range-of-percentage-with-increment-and-count-the-number-of-group%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks