0

I have a csv file which I read using

pd.read_csv()

In the file name I have a column with Female or Male and I would like to create a pie visualization Female or Male. This means, my legend will contain the color and type ( Female or Male) and in the pie chart, there will be the Prozent of each gender.

An example of a data set will be:

['Female', 'Female', 'Female', 'Male', 'Male', 'Female']

A possible solution is to count the number of Female and the number of Male and then to generate the ṕlot.

Is there a simpler way using the dataframe data directly to generate the pie chart?

Eagle
  • 3,362
  • 5
  • 34
  • 46
  • 1
    https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – Paul H Feb 08 '21 at 20:30

1 Answers1

3
s = pd.Series(['Female', 'Female', 'Female', 'Male', 'Male', 'Female'])
s.value_counts(normalize=True).plot.pie(autopct='%.1f %%', ylabel='', legend=True)

enter image description here

Stef
  • 28,728
  • 2
  • 24
  • 52