Kendriya Vidyalaya Ujjain: Submitted By:-Subodhit Chouhan
Kendriya Vidyalaya Ujjain: Submitted By:-Subodhit Chouhan
Submitted by:-
Subodhit Chouhan
PROGRAM-1
PROGRAM:
PROGRAM-2
Aim; Write a program to create a Series object using a
dictionary that
stores the number of students in each section of class 12
in your school?
PROGRAM:
PROGRAM-3
Aim; Consider the series object S that stores the
contribution of each section, as
shown below:
PROGRAM:
#PROGRAM TO CREATE ORIGINAL SERIES
import pandas as pd
df={'A':4300,'B':6500,'C':3900,'D':6100}
s=pd.Series(df)
print(s)
#MODIFICATION IN SERIES
print(‘program after modification’)
s['A']=3400
s['C']=s['D']=5000
print(s)
PROGRAM-4
Aim; Write a program to create a Data Frame Quarterly Sales
where each row
contains the Quarterly Sales of TV, Freeze and AC. Show the
DataFrame
after deleting details of Freeze.
PROGRAM:
#CREATING DATAFRAME
import pandas as pd
df=pd.DataFrame({‘TV’:
[200000,230000,210000,24000],’FREEZE’:\
[3000000,200000,290000,210000],’AC’:
[240000,153000,245000,170000]},\
index=[‘QTR1’,’QTR2’,’QTR3',’QTR4’])
print(df)
#DATAFRAME AFTER DELETING ‘FREEZE’ COLUMN
print(“DataFrame after removing ‘FREEZE’ column “)
del df[‘FREEZE’]
print(df)
PROGRAM-5
PROGRAM:
#CREATING GIVEN DATAFRAME
import pandas as pd
df=pd.DataFrame({‘Roll number’:
[101,102,103,104,105],’name’:[‘karan’,’taran’,’piyush’,\
‘bhupinder’,’simran’],’marks’:[82,85,79,86,94]})
print(df)
#TRANSPOSING DATAFRAME
print(‘Dataframe after transpose’)
print(df.T)
PROGRAM-6
PROGRAM-7
PROGRAM-8
Name=['Anil','Vikas','Arma','Bhupendra','Avnish',
'rajesh']
Acc=[88,82,41,25,50,52]
BST=[97,74,30,62,55,90]
x=np.arange(len(Name))
plt.bar(Name,Acc,label='Accountancy')
plt.bar(x+.2,BST,label='Business studies')
plt.legend(loc='upper right')
plt.show()
PROGRAM-9
PROGRAM:
#CREATING FOLLOWING GRAPH
import matplotlib.pyplot as plt
a=[44.91,58.09,78.07,107.7,138.5,170.6]
b=[449.48,559.51,696.783,870.133,1000.4,1309.1]
x=[a[i]+b[i] for i in range(len(a))]
y=[1960,1970,1980,1990,2000,2010]
plt.xlabel(‘x’)
plt.ylabel(‘y’)
plt.plot(y,x)
plt.title(‘Pakistan India Population till 2010’)
plt.show()
PROGRAM-10
Aim; Write program to plot a bar chart from medals won by four
countries. Make
Sure thet bars are separateky visible
PROGRAM:
#CREATING THE GRAPH
import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(10,7))
info=['Gold','Silver','Bronze','Total']
Australia=[80,59,59,198]
England=[45,45,46,136]
India=[26,20,20,66]
Canada=[15,40,27,82]
x=np.arange(len(info))
plt.bar(info,Australia,width=0.15)
plt.bar(x+.15,England,width=0.15)
plt.bar(x+.30,India,width=0.15)
plt.bar(x+.45,Canada,width=0.15)
plt.show()
PROGRAM-11
21,23,24,24,24,25,25,25,25,26,26,26,27,27,27,27,29,30,30,30,30,
31,33,34,34,
34,35,36,36,37,37,37,38,38,39,40,40,41,41]
Write a program to plot a histogram from above data with 20
PROGRAM:
#PROGRAM TO CREATE FOLLOWING HISTOGRAM
import matplotlib.pyplot as plt
Ages =
[1,1,2,3,5,7,8,9,10,10,11,13,13,15,16,17,18,19,20,21,21,23,24,24,24,
25,
25,25,25,26,26,26,27,27,27,27,27,29,30,30,30,30,31,33,34,34,34,
35,36,36,37,37, 37,38,38,39,40,40,41,41]
plt.hist(Ages,bins=20)
plt.title(“participant’s Ages histogram”)
plt.show()
PROGRAM-12
PROGRAM:
#CREATING ORIGINAL SERIES
import pandas as pd
s=pd.Series(range(100,501,100),index=['I','J','K','L’
‘M'])
print(‘original series’)
print(s)
#RENAMING INDEXES
print(‘Data series after changing indexes’)
s.index=['K','L','M','J','I']
print(s)
PROGRAM-13
PROGRAM:
PROGRAM-14
PROGRAM-15
PROGRAM:
PROGRAM-16
df=pd.DataFrame(d,index(‘Ram’,’Shyam’,’Ra
ma’,’Kashish’,\
‘Mayank’))
df.plot.barh()
plt.ylabel('Names')
plt.xlabel('Height and Weight')
plt.show()
PROGRAM-17
PROGRAM:
#CREATING DATAFRAMNE
import pandas as pd
d={‘Capital’:[True,False,True,True,False],’Density’:
[7,3,4,8,6],’grade’:[‘A’,’C’,’B’,\
‘A’,’B’],’Income’:[70,30,50,90,60],’population’:
[8000,3000,6000,9000,7000]}
df1=pd.DataFrame(d,index=[‘DELHI’,’UDR’,’JPR’,’MUMBAI’,’I
NDORE’])
print(df1)
df1['birthdate']=5
print(df1)
df1.loc['BIKANER']=5
print(df1)
#DELETING COLUMNS ‘population’ AND ‘grade’
df1.drop(["population","grade"],axis=1)
df1.drop(['UDR','MUMBAI'])