English

Collect data about colleges in Delhi University or any other university of your choice and number of courses they run for Science, Commerce and Humanities, store it in a CSV file and present it

Advertisements
Advertisements

Question

Collect data about colleges in Delhi University or any other university of your choice and number of courses they run for Science, Commerce and Humanities, store it in a CSV file and present it using a bar plot.

Code Writing
Advertisements

Solution

import pandas as pd
import matplotlib.pyplot as plt
data = {
    'College': ['Hindu College', 'Hansraj College', 'Miranda House', 'Ramjas College'],
    'Science': [8, 7, 6, 5],
    'Commerce': [3, 4, 2, 3],
    'Humanities': [10, 8, 9, 7]
}
df = pd.DataFrame(data)
df.to_csv("college_courses.csv", index=False)
df = pd.read_csv("college_courses.csv")
df.plot(x='College', y=['Science','Commerce','Humanities'], 
        kind='bar', color=['blue','green','orange'])
plt.title("Number of Courses Offered by Colleges")
plt.xlabel("Colleges")
plt.ylabel("Number of Courses")
plt.show()

Output:
A bar graph will be displayed showing the number of Science, Commerce, and Humanities courses offered by different colleges. The data is first stored in a CSV file named college_courses.csv.

shaalaa.com
  Is there an error in this question or solution?
Chapter 4: Plotting Data using Matplotlib - Exercise [Page 135]

APPEARS IN

NCERT Informatics Practices [English] Class 12
Chapter 4 Plotting Data using Matplotlib
Exercise | Q 11. | Page 135
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×