Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Project FileRonak IP

This document contains a student's classwork assignments on Python Pandas, data visualization, and SQL. It includes 14 programming assignments on Pandas concepts like creating and manipulating series and dataframes. It also includes 5 assignments on data visualization topics such as line graphs, bar graphs, and histograms. Finally, it mentions that assignments were done on SQL string, numeric, and aggregate functions as well as order by and group by clauses.

Uploaded by

ash kathum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Project FileRonak IP

This document contains a student's classwork assignments on Python Pandas, data visualization, and SQL. It includes 14 programming assignments on Pandas concepts like creating and manipulating series and dataframes. It also includes 5 assignments on data visualization topics such as line graphs, bar graphs, and histograms. Finally, it mentions that assignments were done on SQL string, numeric, and aggregate functions as well as order by and group by clauses.

Uploaded by

ash kathum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

St.

Soldier Public School

Session: 2022-23

Name : Ronak Kumar Sharma


Class : XII B
Roll No. :
Subject Code : 065
INDEX
❖ Python Pandas
• Creating Series using python lists
• Create series object Using ndarray
• Create series object using an ndarray that is created by list.
• Create series object using a Dictionary.
• Create and display 2D dictionary which Stores inner
dictionary
• Create a data frame from list Containing performance and
indexing
• Create dataframe containing 2 lists
• Create series and then change the indexes of series object in
any random order
• Change the value of series object at any particular position
• Using iterrows() to extract data from dataframe row wise
• Using iterrows() to row-wise series object
• Using iteritems() to extract data from dataframe column wise
• Using iteritems() to extract data from dataframe column wise
Series Object
• Printing One row at a time in the dataframe
• Print one row value at a time in DataFrame
❖ Data Visualization
• Plotting Line graph in python using x and y labels
• Plotting line graph with customized line width, style and
marker size and edgecolor
• Plot Bar graph with title, defined width, x-y labels and of
different colours
• Plot Bar graph using legnds
• Plot histogram with bins
❖ SQL
• String Functions
• Numeric Functions
• Aggregate Functions
• Order By Clause
• Group By Clause
PR.NO. 1 PG.NO.1

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

Create series object Using ndarray Input:


import pandas as pd import
numpy as np
s=pd.Series(np.linspace(24,64,5)
) print(s)
Output:

PR.NO. 3 PG.NO.3

Create series object using an ndarray that is created by list.

Input:
import pandas as pd
s=pd.Series(np.tile([3,5],2))
print(s)

Output:

PR.NO. 4 PG.NO.4

Create series object using a Dictionary.


Input: import
pandas as pd
student={'A':28,'B':35,'C':30,'D':32}
d=pd.Series(student) print(d)
Output:
PR.NO. 5 PG.NO.5

Create and display 2D dictionary which Stores inner


dictionary.
Input: import
pandas as pd
sales={'yr1':{'qtr1':35000,'qtr2':54660,'qtr3':66000},
\
'yr2':{'qtr1':35200,'qtr2':54670,'qtr3':76000}} dfsales
= pd.DataFrame(sales) print(dfsales) Output:

PR.NO. 6 PG.NO.6

Create a data frame from list Containing performance


and indexing.
Input: import pandas as pd
zoneA={'Target':70000,'sale':72000}
zoneB={'Target':65000,'sale':64000}
zoneC={'Target':68000,'sale':70000}
zoneD={'Target':65000,'sale':60000}
sales=[zoneA,zoneB,zoneC,zoneD]
dfsales=pd.DataFrame(sales,index=['zoneA','zoneB','zoneC','zo
neD']) print(dfsales) Output:

PR.NO. 7 PG.NO.7

Create dataframe containing 2 lists.

Input: import pandas as pd


target=[60000,68000,73000,71000]
sales=[62000,70000,70000,69000]
zonesales=[target,sales]
d=pd.DataFrame(zonesales,columns=['zoneA','zoneB','z
oneC','zoneD'],index=['target','sales']) print(d)
Output:
PR.NO. 8

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

Change the value of series object at any particular


position. Input:
import pandas as pd s4=["A","B","C","D"]
a=pd.Series(s4) print("original data series
s4:") print(a) a[1,3]=[8000,8000] print("series
object s4 after changing values") print(a)
Output:

PG.NO.10

Using iterrows() to extract data from dataframe row


wise: Input: import pandas as pd disales =
PR.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

Using iterrows() to row-wise series object:


Input:
import pandas as pd disales =
{'y1':{'qtr1':35000,'qtr2':54660,'qtr3':66000},\
'y2':{'qtr1':35200,'qtr2':54670,'qtr3':76000},\
'y3':{'qtr1':35500,'qtr2':57660,'qtr3':68000}}
df1=pd.DataFrame(disales)
for(row,rowSeries) in df1.iterrows():
print("Rowindex:",row)
print("Contaning:") i=0 for
value in rowSeries:
print("at",i,"position",value)
i=i+1 print(rowSeries)
Output:

PR.NO. 12 PG.NO.12

Using iteritems() to extract data from dataframe column wise:


Input:
import pandas as pd disales =
{'y1':{'qtr1':35000,'qtr2':54660,'qtr3':66000},\
'y2':{'qtr1':35200,'qtr2':54670,'qtr3':76000},\
'y3':{'qtr1':35500,'qtr2':57660,'qtr3':68000}}
df1=pd.DataFrame(disales)
for(col,colSeries) in df1.iteritems():
print("Columnindex:",col)
print("Contaning:") print(colSeries)
Output:
PR.NO. 13

PG.NO.13

Using iteritems() to extract data from dataframe column


wise Series Object:
Input:
import pandas as pd disales =
{'y1':{'qtr1':35000,'qtr2':54660,'qtr3':66000},\
'y2':{'qtr1':35200,'qtr2':54670,'qtr3':76000},\
'y3':{'qtr1':35500,'qtr2':57660,'qtr3':68000}}
df1=pd.DataFrame(disales) for(col,colSeries) in
df1.iteritems():
Output:
print("Columnindex:",col)
print("Contaning:") i=0 for
value in colSeries:
print("at",i,"position",value)
i+=1 print(colSeries)
PR.NO. 15
PG.NO.14

Printing One row at a time in the dataframe.:


Input: import
pandas as pd
Stu={'Name':['Arsh','Hardeep','Sukchan'],\
'score':[25,19,19]}
df=pd.DataFrame(Stu,index=['A','B','B'])
for(row,rowSeries)in df.iterrows():
print(rowSeries)
print("###############################") Output:
PG.NO.15

Print One column at a time in the dataframe:


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.iteritems():
print(j)
print("###############################") Output:

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:

You might also like