0% found this document useful (0 votes)
15 views34 pages

EEC Notes

Nothing

Uploaded by

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

EEC Notes

Nothing

Uploaded by

khushbusulaniya2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical 1

Problem statement : 1 create a series object using the python sequence with 5
elements:

Solution:
Source code:
import pandas as pd
list=[2,4,6,8,10]
series1=pd.Series(list)
print(series1)

Output:
=== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/series.py ==
0 2
1 4
2 6
3 8
4 10
dtype: int64
Practical 2
Problem Statement1=create a series object using ndarray that has 5 elements in the
range 200 and 300

Solution:
Source code:
import pandas as pd
import numpy as np
s2 = pd.Series(np.arange(200,300,50))
print(s2)
Output:
= RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/practical 2.py
0 200
1 250
dtype: int64
Practical 3
Problem statement:1.create a series object using dictionary to that stores the no of
students in each section of class 12th of your school.

Source code:
import pandas as pd
d1={'A':36,'B':37,'C':68,'D':56,'E':40,'F':55}
s1=pd .Series(d1)
print(s1)

Output:
= RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/practical 2.py
A 36
B 37
C 68
D 56
E 40
F 55
dtype: int64
Practical 4
Problem statement:1 create a series object ‘item’ that stores rate of each product as
given below:
Surf40
Soap50
Sugar60
Write a code to modify rate of surf to 50 and soap to 32,print the changed rate:
Solution:
Source code:
import pandas as pd
s1=pd.Series([40,50,60],['surf','soap','sugar'])
print(s1)
s1['surf']=50
s1['soap']=32
print('after updating the values')
print(s1)

Output:
==== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/123.py ====
surf 40
soap 50
sugar 60
dtype: int64
after updating the values
surf 50
soap 32
sugar 60
dtype: int64

Practical 5
Problem statement: No of students in class 11 and class 12 in three streams (science
,commerce and arts) are stored in 2 series object class 11 and class 12. Write code to find
total no of students in class 11 and class 12 stream wise.

Solution:
Source code:
import pandas as pd
d1={'science':55,'commerce':57,'arts':59}
d2={'science':50,'commerce':45,'arts':50}
class11=pd.Series(d1)
class12=pd.Series(d2)
print(class11)
print(class12)
print('total number of students')
print(class11+class12)

Solution:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
on win32
Enter "help" below or click "Help" above for more information.

==== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/qrs.py ====


science 55
commerce 57
arts 59
dtype: int64
science 50
commerce 45
arts 50
dtype: int64
total number of students
science 105
commerce 102
arts 109
dtype: int64
Practical 6
Problem statement: Create a series ‘temp’ that stores temperature of seven days in it.
index should be ‘Sunday’, ‘Monday’.
Write script to
1. Display temp of first 3 days.
2. Display temp of last 3 days.
3. Display all temp in reverse order like Saturday, Friday,
4. Display temp from Tuesday to Friday.
5. Display square of all temperature

Solution:
Source code:
import pandas as pd
temp=pd.Series([44,42,40,38,36,38,40],index=['sunday','monday','tuesday','wednesd
ay','thursday','friday','saturday'])
print(temp)
print("Temp of first three days\n",temp.head(3))
print("Temp of last three days \n",temp.tail(3))
print("Temp in reverse order\n",temp[::-1])
print("Temp from tuesday to friday\n",temp['tuesday':'friday'])
print("square of all temprature\n",temp*temp)

Output:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
on win32
Enter "help" below or click "Help" above for more information.

==== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/abc.py ====


sunday 44
monday 42
tuesday 40
wednesday 38
thursday 36
friday 38
saturday 40
dtype: int64
Temp of first three days
sunday 44
monday 42
tuesday 40
dtype: int64
Temp of last three days
thursday 36
friday 38
saturday 40
dtype: int64
Temp in reverse order
saturday 40
friday 38
thursday 36
wednesday 38
tuesday 40
monday 42
sunday 44
dtype: int64
Temp from tuesday to friday
tuesday 40
wednesday 38
thursday 36
friday 38
dtype: int64
square of all temprature
sunday 1936
monday 1764
tuesday 1600
wednesday 1444
thursday 1296
friday 1444
saturday 1600
dtype: int64
Practical 7
Problem statement: Create a series object ‘employee’ that stores salary of 7
employees.
1.Total no of elements
2.Series is empty or not
3.Series consist NaN value or not
4.Count Non-NA elements
5.Axis labels :

Solution :
Source code:
import pandas as pd
d1={'radha':5000,'nishu':4500,'jyoti':4000,'tanya':3500,'suhani':3000}
employee=pd.Series(d1)
print(employee)
print("Total no of employees",employee.size)
if employee.empty:
print("Series is empty")
else:
print("Series is not empty")
if employee.hasnans:
print("Series contains NaN elements")
else:
print("Series does not contains NaN elements")
print("Total no of non NA elements",employee.count())
print("Axis labels\n",employee.axes)

Output:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
on win32
Enter "help" below or click "Help" above for more information.

=== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/pr.pty.py ==


Radha 5000
Nishu 4500
Jyoti 4000
Tanya 3500
Suhani 3000
dtype: int64
Total no of employees 5
Series is not empty
Series does not contains NaN elements
Total no of non NA elements 5
Axis labels
[Index(['Radha', 'Nishu', 'Jyoti', 'Tanya', 'Suhani'], dtype='object')]
Practical 8
Problem statement: create the following dataframe ‘sport’ containing sport wise
marks for five students. Use 2D dictionary to create dataframe.

Student Sport Marks


1.Jaya cricket 40
2.riya football 60
3.asha tennis 50
4.pooja kabbadi 30
5.annu hockey 10

Solution:
Source code:
import pandas as pd
d1={'student':['jaya','riya','asha','pooja','annu'],
'sport':['cricket','football','tennis','kabbadi','hockey'],
'marks':[40,60,50,30,10]}
sport=pd.DataFrame(d1,[1,2,3,4,5])
print(sport)

Output:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
on win32
Enter "help" below or click "Help" above for more information.

== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/nishu123.py =
student sport marks
1 jaya cricket 40
2 riya football 60
3 asha tennis 50
4 pooja kabbadi 30
5 annu hockey 10
Practical 9

Problem statement : create a dataframe from list containing dictionaries of most


economical bike with its name and rate of three companies . company name should be the
row table.

Solution:
Source code:
import pandas as pd
list1={'Name':'Sports','cost':50000}
list2={'Name':'bullet','cost':40000}
list3={'Name':'Ferrari','cost':70000}
Bike=[list1,list2,list3]
df=pd.DataFrame(Bike,['TVS','Royal_Enfield','Hero'])
print(df)

Output:
=== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/printy.py ==
Name cost
TVS Sports 50000
Royal_Enfield bullet 40000
Hero Ferrari 70000
Practical 10
Problem statement :: create the following dataframe ‘sales’ containing year wise sales
figure for five sales person in INR. Use the year as column labels, sales person names as row
labels.
2014 2015 2016 2017
1. Madhu 3000 3500 4000 4500
2. Khushi 4000 4500 5000 5500
3. Khushbu 5000 5500 6000 6500
4. Ankita 6000 6500 7000 7500
5. Suhani 7000 7500 8000 8500
Write program to do the followings
1. Display row labels of ‘sales’
2. Display column label of ‘sales’
3. Display last two rows of the ‘sales’
4. Display first two rows of the ‘sales’

Solution:
Source code:
import pandas as pd
dict1={2014:[1000,1500,2000,2500,3000],2015:[2000,1800,2200,3000,4500],
2016:[2400,5000,7000,1000,1200],2017:[2800,5000,6000,7000,9000]},
Sale=pd.DataFrame(dict1,['Madhu','Khushi','Khushbu','Ankita','Shubham'])
print("----DataFrame----")
print(Sale)
print("----Row Labels----")
print(Sale.index)
print("----Column Labels----")
print(Sale.columns)
print("----Bottom two Rows----")
print(Sale.tail(2))
print("----Top two rows----")
print(Sale.head(2))

Output:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
on win32
Enter "help" below or click "Help" above for more information.

=== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/py123.py ===


----DataFrame----
2014 ... 2017
Madhu [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]
Khushi [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]
Khushbu [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]
Ankita [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]
Shubham [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]

[5 rows x 4 columns]
----Row Labels----
Index(['Madhu', 'Khushi', 'Khushbu', 'Ankita', 'Shubham'], dtype='object')
----Column Labels----
Index([2014, 2015, 2016, 2017], dtype='int64')
----Bottom two Rows----
2014 ... 2017
Ankita [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]
Shubham [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]

[2 rows x 4 columns]
----Top two rows----
2014 ... 2017
Madhu [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]
Khushi [1000, 1500, 2000, 2500, 3000] ... [2800, 5000, 6000, 7000, 9000]

[2 rows x 4 columns]
Practical 11
Problem statement ::: create a dataframe ‘cloth’ as given below and write a program
to do followings:
1. Check cloth is empty or not
2. Change cloths such that it becomes its transpose
3. Display no of rows and columns of ‘cloth’
4. Coun and display Non NA values foe each columns
5. Count and display Non NA values for each rows

CName size price

I. Jeans S 2000
II. Pant M 3000
III. Shirt XL 4000
IV. Trouser XXL 300
V. Coat XXXL 200

Solution:
Source code:
import pandas as pd
dict1={'CName':['jeans','pant','shirt','trouser','coat'],
'size':['S','M','XL','XXL','XXXL'],
'price':[2000,3000,4000,300,200]}
cloth=pd.DataFrame(dict1)
print("----DataFrame----")
print(cloth)
print("----checking datafrmae is Empty or not----")
if cloth.empty:
print("cloth is Empty")
else:
print("Cloth is not Empty")
print("----Transpose Dataframe----")
print(cloth.T)
print("----Total no of rows and columns----")
print(cloth.shape)
print("----No of Non NA elements in each column----")
print(cloth.count())
print("----No of Non NA elements in each row----")
print(cloth.count(1))

Output:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
on win32
Enter "help" below or click "Help" above for more information.

======= RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/empty.py


=======
----DataFrame----
CName size price
0 jeans S 2000
1 pant M 3000
2 shirt XL 4000
3 trouser XXL 300
4 coat XXXL 200
----checking datafrmae is Empty or not----
Cloth is not Empty
----Transpose Dataframe----
0 1 2 3 4
CName jeans pant shirt trouser coat
size S M XL XXL XXXL
price 2000 3000 4000 300 200
----Total no of rows and columns----
(5, 3)
----No of Non NA elements in each column----
CName 5
size 5
price 5
dtype: int64
----No of Non NA elements in each row----
0 3
1 3
2 3
3 3
4 3
dtype: int64
Practical 12
Problem statement: create a dataframe ‘cloth’ as given below and write program to
do followings:

• Change the name of ‘trouser’ to ‘pant’ and ‘jeans’ to ‘demin’


• Increase price of all cloth by 10%
• Rename all the indexes to [C001,C002,C003,C004,C005]
• Delete the data of C3 (C003) from the ‘cloth’
• Delete size from ‘cloth’

Solution:
Source code:
import pandas as pd
dict1={'CName':['jeans','pant','shirt','trouser','coat'],
'size':['L','XL','XXL','s','M'],
'price':[1000,200,300,500,600]}
cloth=pd.DataFrame(dict1,index=['C1','C2','C3','C4','C5'])
print("----DataFrame----")
print(cloth)
print("----Change name of trouser to pant----")
cloth.at['C4','CName']='Pant'
#cloth.CName['C4']='Pant'
#cloth.loc['C4','CName']='pant'
print(cloth)
print("----Increase price of all cloth by 10%----")
cloth['price']=cloth['price']+cloth['price']*10/100
print(cloth)
print("----Rename all the indexes to [C001'C002,C003,C004,C005]----")
cloth.rename(index={'C1':'C001','C2':'C002','C3':'C003'
,'C4':'C004','C5':'C005'},inplace='True')
print(cloth)
print("----Delete the data of C003----")
cloth=cloth.drop(['C003'])
print(cloth)
print("----Delete column 'Size'----")
del cloth['size']
print(cloth)

Output:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
on win32
Enter "help" below or click "Help" above for more information.

=== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/CLOTHS.PY ==


----DataFrame----
CName size price
C1 jeans L 1000
C2 pant XL 200
C3 shirt XXL 300
C4 trouser s 500
C5 coat M 600
----Change name of trouser to pant----
CName size price
C1 jeans L 1000
C2 pant XL 200
C3 shirt XXL 300
C4 Pant s 500
C5 coat M 600
----Increase price of all cloth by 10%----
CName size price
C1 jeans L 1100.0
C2 pant XL 220.0
C3 shirt XXL 330.0
C4 Pant s 550.0
C5 coat M 660.0
----Rename all the indexes to [C001'C002,C003,C004,C005]----
CName size price
C001 jeans L 1100.0
C002 pant XL 220.0
C003 shirt XXL 330.0
C004 Pant s 550.0
C005 coat M 660.0
----Delete the data of C003----
CName size price
C001 jeans L 1100.0
C002 pant XL 220.0
C004 Pant s 550.0
C005 coat M 660.0
----Delete column 'Size'----
CName price
C001 jeans 1100.0
C002 pant 220.0
C004 Pant 550.0
C005 coat 660.0
Practical 13
Problem statement : : create a dataframe ‘aid’ as given below and write program to
do followings:
1. Display the books and shoes only
2. Display toys only 3. Display quantity in MP and CG for toys and books.
3. Display quantity of book AP

Toys Books Shoes


MP 300 2000 1000

UP 500 6000 5000

CG 600 5000 6000

AP 900 4000 9000

Solution:
Source code:
import pandas as pd
dict1={'Toys':{'MP':300,'UP':500,'CG':600,'AP':900},
'Books':{'MP':2000,'UP':6000,'CG':5000,'AP':4000},
'Shoes':{'MP':1000,'UP':5000,'CG':6000,'AP':9000}}
aid=pd.DataFrame(dict1)
print('----DataFrame----')
print(aid)
print('----Display the books and shoes only----')
print(aid.loc[:,['Books','Shoes']])
print('----Display toys only----')
print(aid['Toys'])
print('----Display quantity in MP and CG for toys and books----')
print(aid.loc[['MP','CG'],['Toys','Books']])
print('----Display quantity og books in AP----')
print(aid.at['AP','Books'])

Output:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
on win32
Enter "help" below or click "Help" above for more information.

=== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/books.py ===


----DataFrame----
Toys Books Shoes
MP 300 2000 1000
UP 500 6000 5000
CG 600 5000 6000
AP 900 4000 9000
----Display the books and shoes only----
Books Shoes
MP 2000 1000
UP 6000 5000
CG 5000 6000
AP 4000 9000
----Display toys only----
MP 300
UP 500
CG 600
AP 900
Name: Toys, dtype: int64
----Display quantity in MP and CG for toys and books----
Toys Books
MP 300 2000
CG 600 5000
----Display quantity og books in AP----
4000
Practical 14
s

Problem statement: Create a dataframe ‘aid’as given below and write programe to write
the values of ‘aid’to a comma separated file ‘aidfigures.cvs’ on the disk. Do not write the row
labels and column labels.

Toys Books Shoes


MP 200 1000 1800

UP 400 1200 2000

AP 600 1400 2200

CG 800 1600 2400

Solution:
Source code:
import pandas as pd
dict1={'toys':{'Mp':200,'UP':400,'AP':600,'CG':800},
'Book':{'MP':1000,'UP':1200,'AP':1400,'CG':1600},
'shoes':{'MP':1800,'UP':2000,'AP':2200,'CG':2400}}
aid=pd.DataFrame(dict1)
print('----DataFrame----')
print(aid)
aid.to_csv(path_or_buf='C:/Users/ReenaGauri/OneDrive/Desktop/Documents/aidfigures.csv',
header=False, index=False)

Output:
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC
v.1943 64 bit (AMD64)] on win32
Enter "help" below or click "Help" above for more information.

= RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/practical14.py
----DataFrame----
toys Book shoes
Mp 200.0 NaN NaN
UP 400.0 1200.0 2000.0
AP 600.0 1400.0 2200.0
CG 800.0 1600.0 2400.0
MP NaN 1000.0 1800.0

Practical 15
Practical statement:: : The following seat booking are the daily records of a month
December from PVR cinemas.
(110,108,124,198,178,155,145,195,167,138,159,188,173,121,148,154,154,165,156,183,133,
196)
Construct a histogram from above data with 10 bin.

Solution:
Source code:
import pandas as pd
import matplotlib.pyplot as plt
list1=[110,108,124,198,178,155,145,195,167,138,159,188,173,121,148,154,154,165,156,18
3,133,196]
plt.hist(list1)
plt.title("Booking Records @ PVR")
plt.show()

Output:

Practical 16
Practical statement : : Collect and store total medals won by 10 countries in Olympic
games and represent it in form of bar chart with tittle to compare an analyze data.

Solution:
Source code: import matplotlib.pyplot as plt
medals=[100,120,140,160,180,200,220,240,260,280]
country=['China','Amrica','Egypt','Russia','Korea',
'Nepal','Londan','UK','Austria','India']
plt.bar(country,medals)
plt.title('Total olympics medals of ten countries')
plt.show()

Solution:

Practical 17
Problem statement :: Techtipnow Automobiles is authorized dealer of different bikes
companies .They record the entire sale of bikes month wise as given below.

Jan Feb Mar April May June


Royal 300 400 500 600 700 800
enfield
Yamaha 10 20 30 40 50 60
motors
Suzuki 15 30 45 60 75 90
motors
To get proper analysis of sale performance create multiple line chart on a common plot
where all bike sale data are plotted. Display appropriate x and y axis labels, legend and chart
tittle.

Solution:
Source code:
import matplotlib.pyplot as plt
month=['jan','feb','mar','april','may','june']
royalenfield=[300,400,500,600,700,800]
yamhamotors=[10,20,30,40,50,60]
suzukimotors=[100,150,200,250,300,350]
plt.plot(month,royalenfield,label='royal_enfield')
plt.plot(month,yamhamotors,label='yamha_motors')
plt.plot(month,suzukimotors,label='suzuki_motors')
plt.title('Techtipnow Automobiles sale Analysis')
plt.xlabel('Month')
plt.ylabel('No of bikes')
plt.legend( loc='upper center')
plt.show()

Output:
Practical 18
Problem statement :: Given the school result data, analysis the performance of the
student on different parameters, e.g. subject wise or class wise. Create a dataframe for the
above, plot appropriate chart with title and legend.

15 70 60 60 100 70
16 78 30 68 80 50
17 90 50 70 70 60
18 100 70 90 60 98

Solution:
Source code: Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943
64 bit (AMD64)] on win32
Enter "help" below or click "Help" above for more information.

==== RESTART: C:/Users/divya/AppData/Local/Programs/Python/Python313/pltb.py ===


eng math phy chm IT
15 70 60 60 100 70
16 78 30 68 80 50
17 90 50 70 70 60
18 100 70 90 60 98
Output:

You might also like