[Python]how to count the times of each feature in some certain criteria

I would like to sort out the data into two group(cardio=1 and cardio=0) and calculate the
times of each variable. Eventually to create a comparison bar graph where x-axis stands for each variable and y-axis the total times of each variable.
cardio variable value
1.0 cholesterol_ 1.0
1.0 cholesterol_ 1.0
1.0 cholesterol_ 0.0
1.0 gluc_ 0.0
1.0 gluc_ 0.0
1.0 gluc_ 0.0
1.0 smoke 0.0
1.0 smoke 0.0
1.0 smoke 0.0
1.0 alco 0.0
1.0 alco 0.0
1.0 alco 0.0
1.0 active 1.0
1.0 active 0.0
1.0 active 1.0
1.0 overweight_ 1.0
1.0 overweight_ 0.0
1.0 overweight_ 1.0
0.0 cholesterol_ 0.0
0.0 cholesterol_ 0.0
0.0 gluc_ 0.0
0.0 gluc_ 0.0
0.0 smoke 0.0
0.0 smoke 0.0
0.0 alco 0.0
0.0 alco 0.0
0.0 active 1.0
0.0 active 0.0
0.0 overweight_ 0.0
0.0 overweight_ 0.0
its one of the project in Data Analysis with Python Projects (Medical Data Visualizer).
Thank you for reading.

After melting your data you can try .groupby() and .count() methods.

Been stuck on this challenge a few days myself, good luck.

Im still no ther but cant you use dictiinaries?

The number of times the range matches the exact criteria specified!

thank you for the reply.
by using groupby.count i got the follwing
cardio
0.0 12 12
1.0 18 18
whereas not the total number of each feature.

I’m not sure what you have going on, but in the end your dataframe should look like below: (there are many different ways you could get there, the hard part in my opinion was not knowing how it was supposed to be structured)

   cardio variable  value  total
0       0   active      0   6378
1       0   active      1  28643
2       0     alco      0  33080
...
    cardio    variable  value  total
21       1  overweight      1  24440
22       1       smoke      0  32050
23       1       smoke      1   2929
1 Like