PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 29, 2022

[FIXED] how to plot pie chart using data in pandas

 November 29, 2022     jupyter-notebook, pandas, pie-chart     No comments   

Issue

enter image description here

Hi everyone,

I'm relatively new to python. I want to plot a pie chart for department, i.e., how many percent of the employees coming from Sales & Marketing, Operations, Technology, etc...

I'm not sure how to count the total number of employees from respective department first then only fit the data into the pie chart. Any help will be greatly appreciated!


Solution

You can use pandas.Series.value_counts with pandas.Series.plot.pie:

df = pd.DataFrame({"department": ["Sales", "Operations", 
                                  "Sales", "Sales", "Technology"]})
df["department"].value_counts().plot.pie()

Output:

enter image description here



Answered By - Chris
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing