How to generate PIE plot in Python?
DATA VISUALIZATION

How to generate PIE plot in Python?

How to generate PIE plot in Python?

This recipe helps you generate PIE plot in Python

0
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()
    print(format('How to generate PIE plot in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # 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
    plt.axis('equal')
    plt.tight_layout(); plt.show()

Snippet_118()
************************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

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.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

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.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

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

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

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