Professional Documents
Culture Documents
Practical's
Exam – pandas + mysql = 15 marks
Practical file – 5marks
Project – 5 marks
Viva – 5 marks
DATA
HANDLING
IN PANDAS
(25 marks)
session 2020-21
INTRODUCTION TO PANDAS
• Python is an open source Python library providing high
performance data manipulation and analysis tool using
its powerful data structures like series and data frames.
• Pandas stand for PANEL DATA.
• it provides fast data processing as number along with
data manipulation techniques as spreadsheets and
relational databases.
PANDAS DATA TYPES
• Object - it is used for string data type values
A series in pandas can be created using series() method. Also any list / dictionary can be converted
In to series using this method.
import pandas as pd
S=pd.Series([10,12,14,16])
print(S)
S=pd.Series (dict)
print(S)
print()
print(S)
'''WAP TO OBTAIN 5 NUMBER FROM THE
USER IN A LIST AND TEN CREATE A SEIRES
FROM IT AND THEN DISPLAY THE SUM AND
AVERAGE OF ALL THE SERIES ELEMENTS.'''
import pandas as pd
ls=[]
for i in range(1,6):
n=int(input("enter elements "))
ls.append(n)
print("list ")
print(ls)
sr1=pd.Series(ls)
print("SERIES ")
print(sr1)
l=len(sr1)
s=0
av=0
for i in range(0,l):
s=s+sr1[i]
av=s/l
print("sum of seires ",s)
print("average of series ",av)
ACCESSING SERIES INDEX AND VALUES
Index is used to display index values
Values shows the values in a series.
import pandas as pd
Months=['Jan','Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
S1=pd.Series(Months)
print(S1.head(2))
print (S1.tail(3))
SERIES ATTRIBUTES
print("data type ",sr1.dtype)#data type of the seires import pandas as pd
l=[300,150,450,600,250,800,1000]
print("shape ",sr1.shape)#shape of the series in form tuple
sr1=pd.Series(l)
print("dimension ",sr1.ndim)#number of dimension
print(sr1)
print("size ",sr1.size)#number of elements in the series
print("index ",sr1.index)#show the axis label
print("values ",sr1.values)#display values of the seires
print("no of bytes ",sr1.nbytes)#returns number of bytes (int64 and float64= 8 bytes)
print("hasnans ",sr1.hasnans)#gives true if series has any NaN value
print("empty ",sr1.empty)#gives ture is series is empty
print("item size ",sr1[1].itemsize)#return size of each item'''
data type int64
shape (7,)
dimension 1
size 7
index RangeIndex(start=0, stop=7, step=1)
values [ 300 150 450 600 250 800 1000]
no of bytes 56
hasnans False
empty False
item size 8