How do I plot pie chart graph with pandas data

prodoggy4life

I currently have plotted out my pie chart successfully and with this relatively small dataframe. enter image description here

But however, when i try to plot out my pandas pie chart, it looks perfectly fine only until i realise that my index has been included (see the number 0 and 1 at the top right and bottom left corners).

enter image description here

Is there anyway to remove the index? Currently, i'm highly suspicious that the problem comes with the part where i reset and drop my old index.

Here's my code:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# import the csv file
dataname = 'Datasets\\tax-and-penalty-arising-from-audits-by-tax-type.csv'
data = pd.read_csv(dataname)
df = pd.DataFrame(data)

# drop the no_of_cases column since we will not be using it
df2 = df.drop(['tax_and_penalty_arising'],axis=1)

# merge the values: individual income tax and corporate income tax together under tax type together as they can be seen to be seperated in some years eg 2011
dictionary = {'Corporate Income Tax':'Individual and Corporate Income Tax','Individual Income Tax':'Individual and Corporate Income Tax'}
df3 = df2.groupby(['financial_year',df2['tax_type'].replace(dictionary)]).sum().reset_index()

# get only the data from the latest financial_year(2018)
df4 = df3[(df3.financial_year == (2018))]
df4 = df4.reset_index(drop=True)

# # drop the column financial_year as we will not be using it
df4 = df4.drop(['financial_year'],axis=1)

# #  print the dataframe   
print(df4)

# plot out the pie chart
# df4 = df4.drop("index",axis=1)
ax = df4.plot.pie(y='no_of_cases',figsize=(10,10))
ax.legend(labels='tax_type')
plt.pie(df4['no_of_cases'],labels=df4['tax_type'],shadow=False,startangle=90, autopct="%1.1f%%")
plt.show()
Sergey Bushmanov

Starting with defining your df4:

df4 = pd.DataFrame({"tax_type":["GST", "Individual and Corporate Income Tax"], 
                    "no_of_cases":[3145,7001]})

_, ax = plt.subplots(figsize = (10,10))
wedges,_,_ = ax.pie(df4['no_of_cases']
                    ,labels=df4["tax_type"]
                    ,shadow=False,startangle=90, autopct="%1.1f%%"
                    ,textprops={'fontsize': 16})
ax.legend(wedges,df4["tax_type"], loc="upper center", prop={'size': 16});

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Plot pie chart and table of pandas dataframe

How do I find an appropriate position for my labels on a pie chart?

How do I input bar-chart data to an overall pie-chart ? (Highcharts/ JS / jQuery)

Highcharts: How do I set dynamic data to the drilldown pie chart?

How do I plot a bar graph using Pandas?

How to plot pie chart for bivariate data in python

How do I style the series labels on a Highcharts pie chart?

How can I plot data from an external JSON file to a chart.js graph?

How to do I groupby, count and then plot a bar chart in Pandas?

Python: Plot pie chart for every groups in Pandas

how to set two data label for pie chart using core plot

How do I select a region in pie chart (Highcharts)

How do I create a pie chart from VML shapes?

How do I convert this into a pie chart in Excel?

how to plot pie chart in R

How do I create a Hierarchical Pie chart in html and servlet or jsp?

How do i plot histogram and pie chart in R?

how to plot a pie chart?

How do I transfer data from userData in JSON format to a pie chart? ASP.Net Core

How to plot pandas Dataframe as a Pie chart using plotly

How do I plot a graph of previously grouped data?

How do I create a pie chart using categorical data in matplotlib?

How do I control the decimals precision in a plotly/anychart pie chart

How do I use booleans to create dataframe and plot the filtered data on pie chart?

How do you plot scatter graph with chart.js

How do I rearrange the order of pie slices in pandas plot?

how to plot pie chart using data in pandas

How do I replace labels in a legend on a pie chart?

How to plot Django data on a Chart.js graph?