Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Pandas Matplotlib Tutorial to Make Bar Graph Of Excel Files Using Python

Posted on December 18, 2022

 

 

Welcome folks today in this blog post we will be plotting bar graph of excel files using matplotlib and pandas library in python All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the below libraries using the pip command as shown below

 

 

pip install matplotlib

 

 

pip install pandas

 

 

pip install numpy

 

 

After installing all the above libraries you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd
 
import numpy as np
 
import matplotlib.pyplot as plt
 
excel_1_file = "one.xlsx"
 
excel_2_file = 'two.xlsx'
 
df_first_shift = pd.read_excel(excel_1_file,sheet_name="first")
 
df_second_shift = pd.read_excel(excel_1_file,sheet_name="second")
 
df_third_shift = pd.read_excel(excel_2_file)
 
df_all = pd.concat([df_first_shift,df_second_shift,df_third_shift])
 
print(df_all)
 
pivot = df_all.groupby(['shift']).mean()
 
shift_productivity = pivot.loc[:,"Production Run Time (Min)":"Products Produced (Units)"]
 
shift_productivity.plot(kind="bar")
 
plt.show()

 

 

As you can see we are importing the pandas and matplotlib library at the very top.  And as you can see we have two excel files which we are first of all merging with the third one. We are adding all the content of the excel files inside the data frames.  And we are using the method of concat() to concatenate all the dataframes into one. And then we are grouping all the data using the groupby() method to find the pivot element. And then we are calculating the mean() method. And then we are plotting the data in the form of bar graph

 

 

Recent Posts

  • Node.js Express Project to Upload Image Buffer & BLOB Data to MongoDB Database & Display it in Browser Using Javascript
  • Node.js Tutorial to Export Images to PDF Document With Effects Using FilePix Library in Javascript
  • Node.js Tutorial to Export All Pages of PDF Document to Images and Save it in Javascript
  • Node.js OfficeGen Example to Add Text & Images in Powerpoint Presentation in Javascript
  • Node.js OfficeGen Example to Generate Excel Files By Adding Data inside Cells & Sheets in Javascript
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme