'Len() gives zero value when used

I have an object in a data frame containing 0s and 1s, but len() gives zero when I try to count the number of 0s or 1s differently.

count_absence = len(HD1[HD1.diagnosis==0])

count_presence = len(HD1[HD1.diagnosis==1])

print("Percentage of Patients with absence of Heart Disease: {:.2f}%".format((count_absence / (len(HD1.diagnosis))*100)))

print("Percentage of Patients with presence of Heart Disease: {:.2f}%".format((count_presence / (len(HD1.diagnosis))*100)))

Output:

Percentage of Patients with absence of Heart Disease: 0.00%

Percentage of Patients with presence of Heart Disease: 0.00%

len(HD1[HD1.diagnosis==0])

Output:

0

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source