How to generate PIE plot in Python?
DATA VISUALIZATION DATA CLEANING PYTHON DATA MUNGING MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to generate PIE plot in Python?

How to generate PIE plot in Python?

This recipe helps you generate PIE plot in Python

Recipe Objective

Ploting a visual figure of data distribution helps us a lot in analysing a data.

So this is the recipe on how we can generate PIE plot in Python.

Step 1 - Import the library

import pandas as pd import matplotlib.pyplot as plt

We have imported matplotlib.pyplot and pandas which is needed.

Step 2 - Creating 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)

We have created a dictionary with various features and we have passed it through pd.DataFrame to create a dataset.

Step 3 - Ploting Pie Plot

We have created a new feature which will store the sum of all the data of which we want to create Pie Plot. df["total_arrests"] = df["jan_arrests"] + df["feb_arrests"] + df["march_arrests"] print(df) We have made an array of colour code and used it in ploting pie chart. We have ploted Pie cart using Pli.pie by passing the data of which we want to plot it. colors = ["#E13F29", "#D69A80", "#D63B59", "#AE5552", "#CB5C3B", "#EB8076", "#96624E"] 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%%") Finally we are printing the Pie Chart plt.axis("equal") plt.tight_layout(); plt.show()

  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

Download Materials

Relevant Projects

Convolutional RCCn's for extracting the text out of images
CRNNs combine both convolutional and recurrent architectures and is widely used in text detection and optical character recognition (OCR). In this project, we are going to use a CRNN architecture to detect text in sample images. The data we are going to use is TRSynth100k from Kaggle. Given an image containing some text, the goal here is to correctly identify the text using the CRNN architecture. We are going to train the model end-to-end from scratch.

Classification - Zero to hero - Part 1
Classification is one of the basic things in ML and most of us jump to Neural networks or boosting to predict classes. But more often than not, to make the other person understand how the classification is happening, we need to use basic models like Logistic, decision trees etc. In this project we talk about you can apply various basic techniques, the maths and intuition behind them and how they paved way to bagging and boosting of the world

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

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Grouping similar schools/colleges using scorecard and other factors
Use cluster analysis to identify the groups of characteristically similar schools in the College Scorecard dataset. Considerations: Clustering Algorithm Data Preparation How will you deal with missing values? Categorical variables? Feature intercorrelations? Feature normalization or scaling? Dimensionality reduction? Hyperparameters How will you set the parameters -- the algorithm's knobs and dials, so to speak -- in order to achieve valid and useful output? Interpretation Is it possible to explain what each cluster represents? Did you retain or prepare a set of features that enables a meaningful interpretation of the clusters? Do the compositions of the clusters seem to make sense? Validation How will you measure the validity of your clustering process? Which metrics will you use and how will you apply them?

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Loan Eligibility Prediction in Python using H2O.ai
In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.