0% found this document useful (0 votes)
14 views2 pages

Ip Programs

The document contains Python code snippets for data manipulation using pandas and data visualization using matplotlib. It includes creating DataFrames, adding columns, removing columns, and generating bar charts for various datasets. Specific tasks include displaying exam details, student counts, and creating a horizontal bar chart for India's medal tally.

Uploaded by

8201ayush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Ip Programs

The document contains Python code snippets for data manipulation using pandas and data visualization using matplotlib. It includes creating DataFrames, adding columns, removing columns, and generating bar charts for various datasets. Specific tasks include displaying exam details, student counts, and creating a horizontal bar chart for India's medal tally.

Uploaded by

8201ayush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

'''

(i) Create a DataFrame ‘exams’ containing following data using dictionary:


examname dept centres students
SSC CBSE 1100 90000
SSE NIOS 800 45000
NET CBSE 350 28000
SSCE CBSE 1400 160000
CSE UPSC 600 30000
(ii) Display details of SSCE exam.
(iii) Add a column “totstaff” with values: 11000,8000,3500,14000,6000.
(iv) Display students of NET exam. i.e. 28000.
'''

import pandas as pd

exam1 = { 'examname' : [ 'SSC', 'SSE', 'NET', 'SSCE', 'CSE'],


'dept' : [ 'CBSE', 'NIOS', 'CBSE', 'CBSE', 'UPSC'],
'centers' : [ 1100, 800, 350, 1400, 600],
'students' : [ 90000, 45000, 28000, 160000, 30000] }

ex1 = pd.DataFrame (exam1)

print ("Details of Exam")


print (ex1)
print ("Details of Exam SSCE")
print (ex1.loc[3])
print ("Add New column totstaff")
ex1['totstaff']=[11000,8000,3500,14000,6000]
print ("Details student of NET Exam")
print (ex1.students[2])

'''
1 AIM: Consider the given DataFrame:
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
Write suitable Python statements for the following:
i. Add a column called ACC_NO with the following data:
[135,153,225,442].
ii. Add a new Record
iii. Remove the column qty.

'''

import pandas as pd
s1=pd.Series(['P01','P02','P03','P03'])
s2=pd.Series(["Note Book","Pencil Box","Water bottle","School bag"])
s3=pd.Series([85,76,129,730])
s4=pd.Series([500,200,50,70])
d={'Pcd':s1,'title':s2, 'Price':s3, 'qty':s4}
lib=pd.DataFrame(d)
print(lib)
lib["ACC_NO "]=[135,153,225,442]
lib.loc[4]=["p05","bigbook",20,20,501]
print(lib)
lib.drop(["qty"],axis=1,inplace=True)
print(lib)

'''
2 Consider the following data :
Year 2011 2012 2013 2014 2015
Rain(mm)120 130 110 190 140

(i) Create the bar chart of given data.


(ii) Show the Labels on X and Y axis.
(iii) Save the chart as image.
'''

import matplotlib.pyplot as plt


year=[2011,2012,2013,2014,2015]
rain=[120,130,110,190,140]
plt.bar(year,rain)
plt.xlabel("YEAR")
plt.ylabel("RAIN(mm)")
plt.savefig("RAIN.jpg")
plt.show()

'''
AIM: Write a program to create a horizontal bar chart for India's medal tally.
Country Gold Silver Bronze Total
Australia 80 59 59 198
England 45 45 46 136
India 26 20 20 66
Canada 15 40 27 82
'''

import matplotlib.pyplot as plt


Info = ['Gold', 'Silver', 'Bronze', 'Total']
India = [26, 20, 20, 66]
plt.ylabel("Medal type")
plt.xlabel("Medal count")
plt.title("India's Medal Tally in Commonwealth 2018")
X = range (len (Info))
plt.barh(X, India, color = ['gold', 'silver', 'brown', 'black'])
plt.show()

You might also like