Project FileRonak IP
Project FileRonak IP
Session: 2022-23
PYTHON PANDAS
Creating Series using python lists:
Input: import
pandas as pd
l=[5,6,7,8,9,10]
s=pd.Series(l)
print("Series
Object") print(s)
Output:
PR.NO. 2 PG.NO.2
PR.NO. 3 PG.NO.3
Input:
import pandas as pd
s=pd.Series(np.tile([3,5],2))
print(s)
Output:
PR.NO. 4 PG.NO.4
PR.NO. 6 PG.NO.6
PR.NO. 7 PG.NO.7
PG.NO.8
Create series and then change the indexes of series object in any
random order.
Input: import
pandas as pd import
numpy as np
s1=pd.Series(data=[100,200,300,400,500],index=['1','2','3','4',
'5'])
print("original data series:")
print(s1)
s1=s1.reindex(index=['5','4','3','2','1'])
print('data series after changing order of index')
print(s1) Output:
PR.NO. 9
PG.NO.9
PG.NO.10
{'y1':{'qtr1':35000,'qtr2':54660,'qtr3':66000},\
'y2':{'qtr1':35200,'qtr2':54670,'qtr3':76000},\
'y3':{'qtr1':35500,'qtr2':57660,'qtr3':68000},\
'y4':{'qtr1':68000,'qtr2':67000,'qtr3':70000}}
df1=pd.DataFrame(disales)
for(row,rowSeries) in df1.iterrows():
print("Columnindex:",row)
print("Contaning:")
print(rowSeries)
Output:
PR.NO. 11
PG.NO.11
PR.NO. 12 PG.NO.12
PG.NO.13
PR.NO. 16 PG.NO.16
PR.NO. 17
Print one row value at a time in DaraFrame:
Input: import
pandas as pd
Stu={'Name':['Arsh','Hardeep','Sukchan'],\
'score':[25,19,19]}
df=pd.DataFrame(Stu,index=['A','B','B']) for
i,j in df.iterrows():
print(j["score"])
print("~~~~~") Output:
PR.NO. 17 PG.NO.17
DATA VISULIZATION
Plotting Line graph in python using x and y
labels Input: import matplotlib.pyplot as p1
l1=[1,2,3,4,5,6] l2=[1,4,9,16,25,36]
p1.xlabel("Number") p1.ylabel("Sqroot of
Numbers") p1.plot(l1,l2) p1.show() Output:
PR.NO. 18 PG.NO.18
Plotting line graph with customized line width, style and
marker size and edgecolor.
Input: import matplotlib.pyplot as p1 l1=[1,2,3,4,5,6]
l2=[2,5,8,9,6,3] p1.xlabel("busses") p1.ylabel("carss")
p1.plot(l1,'b',linewidth=2.5,marker="+",markersize=10,mark
e redgecolor="b")
p1.plot(l2,'r',linewidth=2.5,linestyle='dashed') p1.show()
Output:
PR.NO. 19 PG.NO.19
Plot Bar graph with title, defined width, x-y labels and of
different colours. Input: import matplotlib.pyplot as p1 import
numpy as np a,b,c = [1,2,3,4],[75,35,45,70],[2,4,6,8]
p1.xlabel('Toys') p1.ylabel('Prince in Rs.') p1.title("Store")
p1.bar(a,b,color=['r','y','b','m'],width=[0.5]) p1.show() Output:
PR.NO. 20 PG.NO.20
Plot Bar graph using legnds Input: import
matplotlib.pyplot as p1 import numpy as np
a,b,c,d = 75,35,45,70 p1.xlabel('Toys')
p1.ylabel('Prince in Rs.') p1.title("Store")
p1.bar(1,a,color=['r'],width=[0.5],label="Car")
p1.bar(2,b,color=['g'],width=[0.5],label="RC
Car")
p1.bar(3,c,color=['b'],width=[0.5],label="Drum")
p1.bar(4,d,color=['c'],width=[0.5],label="Ted")
p1.legend(loc="best") p1.show() Output:
PR.NO. 21
PG.NO.21
Plot histogram with bins. Input:
import matplotlib.pyplot as
plt import numpy as np x=
np.arange(0,50)
y = np.array([14,25,36,22,34,15,16])
z=np.array([3,2,1,6,5,4,9,8]) a =
plt.hist(x,bins=40,cumulative=True)
b = plt.hist(y,bins=10,histtype="barstacked",cumulative=True)
c = plt.hist(z,bins=30,cumulative=True) plt.xlabel("x-axis")
plt.ylabel("y-axi") plt.show() Output:
PR.NO. 22 PG.NO.22
SQL
STRING FUNCTIONS:
PR.NO. 23 PG.NO.23
NUMERIC FUNCTIONS:
AGGREGATE FUNCTIONS:
PR.NO. 24 PG.NO.24
ORDER BY CLAUSE :
GROUP BY CLAUSE: