0

enter image description here Hi,

I'm a beginner in learning how to represent data (in this example, coronavirus deaths) with Python. To do that I use certain libraries like pandas, seaborn, ...

In a circle diagram, I want to display the percentage of total deaths seperated by Female and Male, but I don't really know how to achieve this yet. In online documentation I don't really find much information about this.

Mathias Gielen
  • 91
  • 1
  • 1
  • 4
  • Hi, and welcome to StackOverflow. See this question: https://stackoverflow.com/questions/47320572/pandas-groupby-and-count to see how to group by column 'SEX' and count how many M and how many F. Once you have some code going, we can help you further. – rajah9 May 23 '20 at 12:37

2 Answers2

0

This is what you need:

df.groupby('SEX')["DEATHS"].sum()
Raj Srujan Jalem
  • 613
  • 5
  • 17
0

We present the code that produces the composition ratio.

df.groupby('SEX').sum().apply(lambda x: x / sum(x))

df
    DEATHS
SEX 
F   0.75
M   0.25
r-beginners
  • 31,170
  • 3
  • 14
  • 32