Pandas program to analyze and plot appropriate chart with title and legend.

Write a program to analyze and plot appropriate chart with title and legend for the data frame created below

Program Logic:

  • Import matplotlib.pyplot in program using import statement
  • Import pandas module using import statement
  • Import numpy module using import statement
  • Create Dictionary object using different set of key value pair(i.e. subject and marks scored )
  • Create Dataframe object using DataFrame method and pass index say student name as an argument to it
  • Print DataFrame object using print function
  • Plot bar chart using plot method and pass kind = bar as an argument to it
  • Show bar chart using show method

Below is implementation code/Source code:

Here is code for creating dataframe object and plotting bar chart for given dataframe with output

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
marks  = { "English" :[67,89,90,55],
           "Maths":[55,67,45,56],
            "IP":[66,78,89,90],
           "Chemistry" :[45,56,67,65],
           "Biology":[54,65,76,87]}
df = pd.DataFrame(marks,index=['Sumedh','Athang','Sushil','Sujata'])
print("******************Marksheet****************")
print(df)
df.plot(kind='bar')
plt.title("Bar Graph for Result Analysis")
plt.xlabel("Student Name ")
plt.ylabel("Marks")
plt.show()

Below is Output:

******************Marksheet****************
        English  Maths  IP  Chemistry  Biology
Sumedh       67     55  66         45       54
Athang       89     67  78         56       65
Sushil       90     45  89         67       76
Sujata       55     56  90         65       87

Below is Snapshot of Executable code with output:

Below is Bar chart of result analysis

You can also check:

Write a program to create data frame quarterly sales where each row contain the item category, item name and expenditure. Group the row by the category and print the total expenditure per category.

Write a program to create data frame based on e-commerce data and generate descriptive statistics.

Write a program to create data frame for examination result and display row labels, column labels data types of each column and the dimensions.

Write a Pandas program to select the rows where the number of attempts in the examination is greater than 2.

<