Practical File Informations Practices Name Aditya Kaushik CLASS 12 A ADMI - NO. 6934

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

PRACTICAL FILE

INFORMATIONS PRACTICES

NAME =ADITYA KAUSHIK

CLASS =12TH A

ADMI.NO.=6934
SUBMITTED TO. = MR.MANISH SIR
Series Program
1. A program to create series from two list

import pandas as pd
s1=['Maths','IP','ECO','ENGLISH']
s2=[89,84,92,86]
s3=pd.Series(s2,index = s1)
print(s3)
output

Made by : Aditya
2. Program to create series using ndarray and dictionary

import pandas as pd
import numpy as np
array1=np.array([12,13,14])
dict1={'aditya':98,'kunal':87,'ram':99}
s1=pd.Series(dict1)
s2=pd.Series(array1)
print(s1,s2)
output

Made by : Aditya
3. Program to show the attributes of a series
import pandas as pd
s1=pd.Series(range(1,19,3),index=[x for x in 'ADITYA'])
print(s1)
s1.shape
s1.index
s1.size

output
Made by : Aditya
4. Program to create two series S1 and S2 Write a Python
program to add, subtract, multiple and divide two Pandas
Series

import pandas as pd
s1 = pd.Series([10,20,30,40])
s2 = pd.Series([50,60,70,80])
print(s1,s2)
print(s1+s2)
print(s1-s2)
print(s1*s2)
print(s1/s2)
output
Made by : Aditya
5. Three Series objects stores the marks of 10 students in three terms.
Roll numbers of students form the index of these Series objects.
The Three Series objects have the same indexes. Calculate the total
weighted marks obtained by students as per following formula :
Final marks = 25% Term 1 + 25% Term 2 + 50% Term 3 Store the
Final marks of students in another Series object

import pandas as pd
roll = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
T1 = pd.Series([98, 75, 99, 100, 95, 64, 33, 76, 79, 80], index=roll)
T2 = pd.Series([84, 89, 69, 89, 90, 90, 65, 60, 72, 100], index=roll)
T3 = pd.Series([89, 73, 79, 70, 92, 99, 93, 86, 98, 85], index=roll)
FM = pd.Series(0.25*T1 + 0.25*T2 + 0.5*T3)
print(FM)

Made by : Aditya
output

6. A program to show the methods(head(),count(),tail()) of a series

import pandas as pd
s1 = pd.Series([10,20,30,40],index=['a','b','c','d'])
print(s1)
print(s1.head(2))
print(s1.tail(2))
print(s1.count)
output

Made by : Aditya
7. program to generate a series of 5 elements of multiples of 7
starting with 35 with index multiply by 3.

import pandas as pd
import numpy as np
a=35
n = np.arange(a,a*2,7)
s = pd.Series(index=n*3,data=n)
print(s)
Made by : Aditya
output

Made by : Aditya
Datafram program
1.Write a program to create datafram from dictionay of list and list of
dictionary.
import pandas as pd
Student={'name':['aditya','rahul','ajay'],'ip':[67,45,34],'economics':[89,78,67]}
df=pd.DataFrame(Student)
print(df)
newstudent=[{'aditya':99,'kunal':97,'pankaj':88},
{'aditya':89,'kunal':77,'pankaj':65},
{'aditya':70,'kunal':88,'pankaj':74}]
newdf =pd.DataFrame(newstudent)
print(newdf)

Made by : Aditya
2.Write a program to display use of various attribute of data frame
import pandas as pd
student={'Name':['Kunal','Aditya','Lakshay','Rachit'], 'English':[89,78,87,77], 'Maths':[77,78,81,75], 'IP':[87,88,96,89]}
df=pd.DataFrame(student)
print(df)
print(df.index)
print(df.columns)
print(df.dtypes)
print(df.size)
print(df.shape)
print(df.ndim)
print(df.count())

Made by : Aditya
3. Write a program to create a dataframe of the class and accept the
roll number of the child ( given as index) from the user and display all
his details.
• The program must continue executing till the user wants. The program
must
• give a valid output if the roll number entered for searching is not there in
the dataframe

import pandas as pd
student={'Name':['Kunal','Aditya','Lakshay','Rachit'], 'English':[89,78,87,77], 'Maths':[77,78,81,75], 'IP':[87,88,96,89]}
df=pd.DataFrame(student)
print(df)
print("Dataframe After adding new row")
df.loc['4']=['Nitin','56','67','75',]
print(df)
print("Dataframe After adding new column")
df['History']=['87','78','88','89','78']
print(df)

Made by : Aditya
4. Write a program to Add column and row in existing Data frame
import pandas as pd
import numpy as np
array=np.array([[68,89,45,98],[89,56,95,89],
[65,89,97,94],[94,95,93,92]])
column_values=['eco','maths','Ip','math']
df=pd.DataFrame(data=array,columns=column_values)
print(df)
print('inserting new record')
df['qualify']=['no','yes','yes','no']
df.loc['4']=[45,56,68,95,'yes']
print(df)

Made by : Aditya
5.Create the Dataframe sales containing year wise sales figures for
five sales person in INR .use the years as column label and sales
person name as row labels.
import pandas as pd
inr2014=[700,2100,1300,878,987]
inr2015=[700,2100,1310,878,978]
inr2016=[5000,2100,1350,878,977]
inr2017=[700,2150,1370,878,987]

label=['ADITYA','KUNAL','MANISH','RACHIT','LAKSHYA']
dic={'2014':inr2014,'2015':inr2015,'2016':inr2016,'2017':inr2017}
Sales = pd.DataFrame(dic,index=label)
print(Sales)

Made by : Aditya
Made by : Aditya
Made by : Aditya
Made by : Aditya

You might also like