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

Saturday, April 23, 2022

[FIXED] how to create a pie chart from csv file using python

 April 23, 2022     matplotlib, pandas, pie-chart, plot, python     No comments   

Issue

I have this CSV data file, I'm trying to make a pie chart using this data

I'm a beginner in python and don't understand how to create a pie chart using the three columns, please help!

working solution code would be more helpful!

My code:

import pandas as pd
import matplotlib.pyplot as plt 

df = pd.read_csv ('chart_work.csv')

product_data = df["Product Name;"]   
bug_data = df["Number Of Bugs"]                      
colors = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#8c564b"]    

plt.pie(bug_data , labels=product_data , colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)

plt.show()

the pie chart which is outputed by this code is distorted, any help?

Chart I'm getting:

enter image description here


Solution

This is very simple.

import pandas as pd
from matplotlib.pyplot import pie, axis, show
%matplotlib inline

df = pd.read_csv ('chart_work.csv')

sums = df.groupby(df["Product Name;"])["Number Of Bugs"].sum()
axis('equal');
pie(sums, labels=sums.index);
show()

enter image description here



Answered By - Ashok Rayal
Answer Checked By - Terry (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