Exercise on Pandas DataFrame Plots

Pandas , Pandas plot

Download student.xlsx file

  1. Read the data from Excel table and plot a line graph showing Number of students in each class.
  2. Plot bar graph showing Class and its Mean mark of each class.
  3. Plot bar graph showing Class and its Mean mark and Maximum mark of each class.
  4. Create a Pie chart showing Class and number of students.
  5. Create a density plot by using Mark
Solution 1
import pandas as pd 
my_data = pd.read_excel('D:\student.xlsx',index_col='id')
df=my_data['class1'].value_counts()
#print(my_out)
df.plot.line(title="Class and number of Marks");
Solution 2
import pandas as pd 
my_data = pd.read_excel('D:\student.xlsx',index_col='id')
df=my_data[['class1','mark']].groupby(['class1']).agg(['mean'])
df.plot.bar(title="Class1 and Mean mark");
Solution 3
import pandas as pd 
my_data = pd.read_excel('D:\student.xlsx',index_col='id')
df=my_data[['class1','mark']].groupby(['class1']).agg(['mean','max'])
df.plot.bar(title="Class with Mean and Max mark");
Solution 4
import pandas as pd 
my_data = pd.read_excel('D:\student.xlsx',index_col='id')
df=my_data['class1'].value_counts()
#print(my_out)
df.plot.pie(title="Class with number of students");
Solution 5
import pandas as pd 
my_data = pd.read_excel('D:\student.xlsx',index_col='id')
df=my_data['mark']
#print(my_out)
df.plot.density(title="Mark Density");



Pandas plot

Plotting graphs using DataFrame
plot-linePlotting line graph with different options
plot-barPlotting bar graph with different options
plot-barhPlotting Horizontal bar graph with different options
plot-histHistogram with different options
plot-boxplotboxplot with different options
plot-piePie diagram with different options
plot-densityDensity diagram with different options
plot-areaArea diagram with different options
plot-scatterScatter plot with different options

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer