How to generate PIE plot in Python?

How to generate PIE plot in Python?

How to generate PIE plot in Python?

This recipe helps you generate PIE plot in Python

This python source code does the following : 1. Creates and converts data dictionary into dataframe 2. Plots pie chart graphs using matplotlib for visualization 3. Uses maniplation of parameters for making the graphs more interactive
In [2]:
## How to generate PIE plot in Python
def Snippet_118():
    print(format('How to generate PIE plot in Python','*^82'))

    import warnings

    # load libraries
    import pandas as pd
    import matplotlib.pyplot as plt

    # Create dataframe
    raw_data = {'officer_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
                'jan_arrests': [4, 24, 31, 2, 3],
                'feb_arrests': [25, 94, 57, 62, 70],
                'march_arrests': [5, 43, 23, 23, 51]}
    df = pd.DataFrame(raw_data, columns = ['officer_name', 'jan_arrests',
                                           'feb_arrests', 'march_arrests'])
    print(); print(df)

    # Create a column with the total arrests for each officer
    df['total_arrests'] = df['jan_arrests'] + df['feb_arrests'] + df['march_arrests']
    print(); print(df)

    # Create a list of colors (from iWantHue)
    colors = ["#E13F29", "#D69A80", "#D63B59", "#AE5552", "#CB5C3B", "#EB8076", "#96624E"]

    # Create a pie chart
    plt.pie(df['total_arrests'], labels=df['officer_name'], shadow=False,
            colors=colors, explode=(0, 0, 0, 0, 0.15), startangle=90, autopct='%1.1f%%')

    # View the plot drop above

************************How to generate PIE plot in Python************************

  officer_name  jan_arrests  feb_arrests  march_arrests
0        Jason            4           25              5
1        Molly           24           94             43
2         Tina           31           57             23
3         Jake            2           62             23
4          Amy            3           70             51

  officer_name  jan_arrests  feb_arrests  march_arrests  total_arrests
0        Jason            4           25              5             34
1        Molly           24           94             43            161
2         Tina           31           57             23            111
3         Jake            2           62             23             87
4          Amy            3           70             51            124

Relevant Projects

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.