Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a pie chart from csv file using python

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

like image 976
Ganesha Avatar asked Oct 26 '25 00:10

Ganesha


1 Answers

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

like image 92
Ashok Rayal Avatar answered Oct 27 '25 16:10

Ashok Rayal