Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

I.

P PRACTICALS

SAKSHI
XII-B
18
(1)Write a program in a series list for following
numbers:100,405,607,467.

Import pandas as pd

S=pd.Series([100,405,607,467])

print(S)
(2)Write a code to find maximum and minimum
areas, with a total of all straight areas.

import pandas as pd

Area=[30,40,50,60]

S=pd.Series(Area,index=[‘Goa’,’U.P.’,’Punjab’,’Harya
na’])

print(S)
(3)Write a program to create a series as “S1” with
names, values, and marks of term 1. Also, create
another series with the name “S2” with names,
values, and marks of term 2.

Show the total of both.

Import pandas as pd
Marks=[30,45,60,80]
S=pd.Series(Marks,index=['yash','ria','sonu','k
alu'])
print(S)
(4) Create a menu-driven program for areas of
some states given in series. Try out some
functions too.

import pandas as pd
print('1 to create a series')
print('2 to display the index')
print('3 to display dimensions')
print('4 to display the size')
area=[30,40,50,60]
S=pd.Series(area,index=['goa','UP','MP','HP'])
op=int(input('enter your choice'))
if op==1:
print(S)
elif op==2:
print(S.index)
elif op==3:
print(S.ndim)
else:
print('invalid option')
(5)Create a menu-driven program with names and
quantity of books. Also, try some functions in the
program for the series.

import pandas as pd
print('1 to create a series')
print('2 to display the datatype of series
values')
print('3 to display the total bytes in a series')
print('4 to display the size of series')
books=[200,100,500,300]
S=pd.Series(books,index=['circe','ikigai','harr
y potter','wings of fire'])
op=int(input('enter your choice'))
if op==1:
print(S)
elif op==2:
print(S.dtype)
elif op==3:
print(S.nbytes)
elif op==4:
print(S.size)
else:
print('invalid option')
(6)Create a data frame for roll numbers 1-4
with their class,marks, and names.

import pandas as pd
L=[[1,'A','X1',40],[2,'B','XI',70],[3,'C','XII',80],
[4,'D','XII',60]]
df=pd.DataFrame(L,index=[1,2,3,4],columns=
['Roll no.','Name','Class','Marks'])
print(df)
(7)Create a dataframe with the price and
quantity of some stationary objects.

import pandas as pd
D={'Pid':['P01','P02','P03','P04'],'Pname':
['erase','pencil','pen','scale'],'Pprice':
[5,15,25,10],'Pquantity':[100,200,150,100]}
df=pd.DataFrame(D,index=[1,2,3,4])
print(df)
(8)Create a data framefor 5 employees with
names and salaries.

import pandas as pd
D={'name':
['Ayush','Betty','Catherine','Dhruv','Emily'],'sa
lary':[40000,50000,35000,60000,65000]}
df=pd.DataFrame(D,index=[1,2,3,4,5])
print(df)
(9)Create a menu-driven program to give
options to the user to;-
(a) create a dataframe with student names,
class, and roll no.
(b)display the index
(c) to display the value of given data

import pandas as pd
print('1 to create a dataframe')
print('2 to display the index')
print('3 to display the values of the
dataframe')
D={'roll no.':[1,2,3,4],'names':
['sia','mia','ria','jia'],'class':['XII','XI','XII','XI']}
df=pd.DataFrame(D)
op=int(input('enter your choice'))
if op==1:
print(df)
elif op==2:
print(df.index)
elif op==3:
print(df.values)
(10) Write a menu-driven program to show at
least 3 dataframe options.

import pandas as pd

print('1 to create a dataframe')

print('2 to display the index')

print('3 to display dimensions')

print('4 to display the size')

D={'roll no.':[1,2,3,4],'names':
['sia','mia','ria','jia'],'class':['XII','XI','XII','XI']}

df=pd.DataFrame(D)

op=int(input('enter your choice'))

if op==1:

print(df)

elif op==2:

print(df.index)

elif op==3:

print(df.ndim)

elif op==4:

print(df.size)
(11)WAP to draw a bar graph for a numpy
series using different colors.
import matplotlib.pyplot as plt
import numpy as np
p=np.array([1,2,3,4])
plt.bar(p,p*2,color='r', width=0.3)
n=(p+3)*2-5
plt.bar(p+0.3,n, color='b', width=0.3)
plt.xticks([11,12,13,15])
plt.yticks([10,14,17,16])
plt.show()
(12)Write a program creating a data frame
with test no., comparing marks of 2 students
using 2 different bar graphs. Include legend
too.
import pandas as pd

import matplotlib.pyplot as plt

D={'test':[1,2,3,4],'rahul':[88,87,97,67],'suman':
[92,95,82,91]}

df=pd.DataFrame(D)

print(df)

x=df['test']

y=df['rahul']

z=df['suman']

plt.subplot(2,1,1)

plt.bar(x,y,color='c',label='Rahul',width=0.4)

plt.xlabel('tests')

plt.ylabel('scores')

plt.legend()

plt.subplot(2,1,2)

plt.bar(x+0.4,z,color='r',label='suman',width=0.4)

plt.xlabel('tests')

plt.ylabel('scores')
plt.legend()

plt.show()
(13)Make a data frame with ages of 10 men
and women and make a line chart with
varying colors to differentiate.

import pandas as pd

import matplotlib.pyplot as plt

D={'men':[13,35,68,14,22,43,77,56,91,17],

'women':[11,26,46,40,77,61,27,68,10,39]}

people=pd.DataFrame(D)

print(people)

x=people.index

y=people['men']

z=people['women']

plt.plot(x,y,'p',label="men age",linestyle="--",
linewidth=7,marker='*’,markeredgecolor='yellow',m
arkersize=15, markerfacecolor='r')

plt.plot(x,z,'r', label="women age", linestyle=":",


linewidth=4,marker='*',markeredgecolor='green',m
arkersize=10, markerfacecolor='b')

plt.xlabel('index')

plt.ylabel('peoples age')

plt.legend()
plt.grid(True)

plt.show()
(14)Write a program to display a bar graph
with different classes and students in each.
import pandas as pd

import matplotlib.pyplot as plt

D={'class':['xii','xi','x'],'students':[21,34,66]}

df=pd.DataFrame(D)

print(df)

x=df['class']

y=df['students']

plt.bar(x,y)

plt.show()
(15)Write a program with a data frame of 2 student
scores and create a bar graph to compare both
barks along with different colours and a legend.

import pandas as pd

import matplotlib.pyplot as plt

D={'Tests':[1,2,3,4],'Rahul':[87,93,88,95],'Suman':
[95,88,92,94]}

df=pd.DataFrame(D)

x=df['Tests']

y=df['Rahul']

z=df['Suman']

plt.bar(x,y,color='c',width=0.4,label='Rahul')

plt.bar(x+0.4,z,color='r',width=0.4,label='Suman')

plt.xlabel('Tests')

plt.ylabel('scores')

plt.legend()

plt.show()
(16)Create a dataframe with year and
process of stock and market.
import pandas as pd

D={'year':[2001,2002,2003,2004],'stock price':
[10000,20000,30000,40000],'market price':
[15000,25000,35000,45000],}

df=pd.DataFrame(D)

print(df)
(17) Use both numpy and pandas library with
certain values to create a dataframe.

import pandas as pd

D={'shop':['gadaelectronics','tata
sales','hampy','shampy'],'loss':
[10000,20000,30000,40000],'profit':
[15000,25000,35000,45000]}

df=pd.DataFrame(D)

print(df)
(18)Create a data frame using NumPy and pandas
library and insert null values.Also use functions to:

 dropna()
 Fillna()
 Isnull()
 Iterrows()

import pandas as pd

import numpy as np

D={'name':['A','B','C','D'],'age':[25,27,35,31],'gender':
['F','M','F','F'],'project':
['genetics',np.NaN,'rusting','code'],'budget':
[120000,np.NaN,np.NaN,50000]}

df=pd.DataFrame(D)

print(df)
for i in df.iterrows():

print(i)

for i in df.iteritems():

print(i)
(19)Draw out a data frame with 6 records each in 3
rows and use the code to write the total of each.

import pandas as pd
D={'HOUSE':
['chenab','ganges','jamuna','jhelum','ravi','satluj'],'FI
RST':[5,10,8,12,3,7],'SECOND':
[7,5,13,11,5,6],'THIRD':[6,14,15,12,10,3]}

df=pd.DataFrame(D)

print(df)

df['total']=df["FIRST"]+df['SECOND']+df['THIRD']

print(df)

(20) W.A.P. for creating a dataframe.

import pandas as pd

D={'studentid':[2334,2535,2637,1526],"homework":
[10,20,10,15],'midterm':[78,75,73,76],'project':
[5,4,3,2]}
df=pd.DataFrame(D)

print(df)

You might also like