0% found this document useful (0 votes)
11 views10 pages

LIst of practicals 2024 - 25 class xii

Practicals

Uploaded by

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

LIst of practicals 2024 - 25 class xii

Practicals

Uploaded by

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

#1.

Create a series object using List

import pandas as p

s1=p.Series(['Aman','Aditya','Chitransh','Krishiv','Anushka'])

print(s1)

Output:

0 Aman

1 Aditya

2 Chitransh

3 Krishiv

4 Anushmka

# 2. Create a series object using List with labelled index

import pandas as p

s1=p.Series(['Aman','Aditya','Chitransh','Krishiv','Anushmka'],index=['a','b','c','d','e'])

print(s1)

Output:

a Aman

b Aditya

c Chitransh

d Krishiv

e Anushmka
# 3. Create a series object using Dictionary

import pandas as p

s1=p.Series({'Punjab':'Chandigarh','UP':'Lucknow','Rajasthan':'Jaipur','Mahrashtra':'Mumbai'})

print(s1)

Output:
Punjab Chandigarh

UP Lucknow

Rajasthan Jaipur

Mahrashtra Mumbai

# 4. Create a series object using Numpy Array

import pandas as p

import numpy as np

s1=p.Series(np.array(['India','Pakistan','Nepal','Bhutan']))

print(s1)

Output:
0 India

1 Pakistan

2 Nepal

3 Bhutan

# 5. Program to Access Series Elements using Positional Index

import pandas as pd

s1=pd.Series(['India','USA','UK','France','Russia'])

print(s1[2])

Output:

UK
# 6. Program to Access Series Elements using Slicing Positional Index

import pandas as pd

s1=pd.Series(['India','USA','UK','France','Russia'])

print(s1[1:3])

Output:

1 USA

2 UK

# 7. Program to Access Series Elements using Slicing labelled index

import pandas as pd

s1=pd.Series(['India','USA','UK','France','Russia'],index=['a','b','c','d','e'])

print(s1['a':'c'])

Output:

a India

b USA

c UK

# 8. Program to Access Series Elements using head method

import pandas as pd

s1=pd.Series([10,20,30,40,50,60,70,80])

print(s1.head(3))

Output

0 10

1 20

2 30
# 9. Program to Access Series Elements using tail method

import pandas as pd

s1=pd.Series([10,20,30,40,50,60,70,80])

print(s1.tail(3))

Output

5 60

6 70

7 80

# 10. Program to add two series

import pandas as pd

s1=pd.Series([10,20,30],index=['a','b','c'])

s2=pd.Series([100,200,300],index=['b','c','d'])

print(s1+s2)

Output:

a NaN

b 120.0

c 230.0

d NaN
#11. Addition of two series using add method with fill_value attribute

import pandas as pd

s1=pd.Series([10,20,30],index=['a','b','c'])

s2=pd.Series([100,200,300],index=['b','c','d'])

print(s1.add(s2,fill_value=0))

Output:

a 10.0

b 120.0

c 230.0

d 300.0

#12. Creation of Data Frame using dictionary of list

import pandas as p

l1=[1,2,3]

l2=['Harry','Simran','Gurpreet']

l3=[87,97,94]

df=p.DataFrame({'Rollno':l1,'Name':l2,'Marks':l3})

print(df)

Output:

Rollno Name Marks

0 1 Harry 87

1 2 Simran 97

2 3 Gurpreet 94
#13. Creation of Data Frame using list of dictionaries

import pandas as p

d1={'PId':1,'PName':'Maggi','Price':20}

d2={'PId':2,'PName':'Burger','Price':50}

d3={'PId':3,'PName':'Pizza','Price':200}

df=p.DataFrame([d1,d2,d3])

print(df)

Output:

PId PName Price

0 1 Maggi 20

1 2 Burger 50

2 3 Pizza 200

# 14. Program to add a new Column in the DataFrame

import pandas as pd

d1={'RNO':1,'Name':'Abc','Marks':98}

d2={'RNO':2,'Name':'xyz','Marks':92}

df=pd.DataFrame([d1,d2])

print(df)

df['Address']=['India','UK']

print(df)

Output:

RNO Name Marks

0 1 Abc 98

1 2 xyz 92

RNO Name Marks Address

0 1 Abc 98 India

1 2 xyz 92 UK
#15. Program to add a new row in the DataFrame

import pandas as p

d1={'RNo':1,'Name':'abc','Marks':98}

d2={'RNo':2,'Name':'xyz','Marks':87}

df=p.DataFrame([d1,d2])

print(df)

df.loc[2]=[3,'pqr',78]

print(df)

Output:

RNo Name Marks

0 1 abc 98

1 2 xyz 87

RNo Name Marks

0 1 abc 98

1 2 xyz 87

2 3 pqr 78

#16 Program to delete column in the DataFrame

import pandas as p

d1={'RNo':1,'Name':'abc','Marks':98}

d2={'RNo':2,'Name':'xyz','Marks':87}

df=p.DataFrame([d1,d2])

print(df)

df=df.drop('Marks',axis=1)

print(df)

Output:

RNo Name Marks

0 1 abc 98

1 2 xyz 87
RNo Name

0 1 abc

1 2 xyz

#17. Program to delete row in the DataFrame

import pandas as p

d1={'RNo':1,'Name':'abc','Marks':98}

d2={'RNo':2,'Name':'xyz','Marks':87}

df=p.DataFrame([d1,d2],index=['a','b'])

print(df)

df=df.drop('b',axis=0)

print(df)

Output

RNo Name Marks

a 1 abc 98

b 2 xyz 87

RNo Name Marks

a 1 abc 98

#18. Program to rename column in the DataFrame

import pandas as p

d1={'RNo':1,'Name':'abc','Marks':98}

d2={'RNo':2,'Name':'xyz','Marks':87}

d3={'RNo':3,'Name':'pqr','Marks':93}

df=p.DataFrame([d1,d2,d3])

print(df)

df=df.rename({'RNo':'RollNo','Name':'StudentName'},axis=1)

print(df)
Output:

RNo Name Marks

0 1 abc 98

1 2 xyz 87

2 3 pqr 93

RollNo StudentName Marks

0 1 abc 98

1 2 xyz 87

2 3 pqr 93

#19. Program to rename row index in the DataFrame

import pandas as p

d1={'RNo':1,'Name':'abc','Marks':98}

d2={'RNo':2,'Name':'xyz','Marks':87}

d3={'RNo':3,'Name':'pqr','Marks':93}

df=p.DataFrame([d1,d2,d3],index=['a','b','c'])

print(df)

df=df.rename({'a':'x'},axis=0)

print(df)

RNo Name Marks

a 1 abc 98

b 2 xyz 87

c 3 pqr 93

RNo Name Marks

x 1 abc 98

b 2 xyz 87

c 3 pqr 93
#20. Program to access column from the DataFrame

import pandas as p

d1={'RNo':1,'Name':'abc','Marks':98}

d2={'RNo':2,'Name':'xyz','Marks':87}

d3={'RNo':3,'Name':'pqr','Marks':93}

df=p.DataFrame([d1,d2,d3],index=['a','b','c'])

print(df[['Name','Marks']])

Output

Name Marks

a abc 98

b xyz 87

c pqr 93

#21. Program to access rows from the DataFrame

import pandas as p

d1={'RNo':1,'Name':'abc','Marks':98}

d2={'RNo':2,'Name':'xyz','Marks':87}

d3={'RNo':3,'Name':'pqr','Marks':93}

df=p.DataFrame([d1,d2,d3],index=['a','b','c'])

print(df.loc['b':'c'])

Output

RNo Name Marks

b 2 xyz 87

c 3 pqr 93

You might also like