0% found this document useful (0 votes)
7 views21 pages

63 Updated Python Upadated Skilllab

The document outlines Experiment 9 and Experiment 10 from a laboratory course in Electronics and Telecommunication Engineering, focusing on Python Tkinter and SQLite. Experiment 9 involves creating a GUI application using Tkinter to display frames, message boxes, buttons, and list boxes, while Experiment 10 covers database operations using SQLite, including creating tables and inserting data. Both experiments emphasize practical programming skills in Python and the use of relevant libraries for GUI and database management.
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)
7 views21 pages

63 Updated Python Upadated Skilllab

The document outlines Experiment 9 and Experiment 10 from a laboratory course in Electronics and Telecommunication Engineering, focusing on Python Tkinter and SQLite. Experiment 9 involves creating a GUI application using Tkinter to display frames, message boxes, buttons, and list boxes, while Experiment 10 covers database operations using SQLite, including creating tables and inserting data. Both experiments emphasize practical programming skills in Python and the use of relevant libraries for GUI and database management.
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
You are on page 1/ 21

(PermanentlyAffiliatedtoUniversityof Mumbai)

DepartmentofElectronicsand TelecommunicationEngineering

EXPERIMENTNUMBER 9

EXPERIMENTNAME PythonTkinterprogramto:
DisplayFramesinPythonusingTkinter.
DisplayMessageboxandbuttoninPython usingTkinter.
Createsimplecalculatorwhichperformsaddition.
DisplayListboxinPython usingTkinter.

DATE OF
PERFORMANCE

DATEOFCORRECTION

SIGN&DATE

GRADE

TIMELY LAB
ATTENDANCE CORRECTION PERFORMANCE ORAL TOTAL

ALLOTTED 2 2 3 3 10

OBTAINED

LABORATORY:SIGNAL PROCESSINGLAB 63
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

EXPERIMENT09

AIMOFEXPERIMENT:PythonTkinterprogram to:
DisplayFramesinPythonusing Tkinter.
DisplayMessageboxandbuttonin Python usingTkinter.
Createsimplecalculatorwhich performs addition.
Display Listbox in Python using Tkinter.

SOFTWARE/EQUIPMENT:PC,PythonIDLE.

THEORY:-

❖ GRAPHICALUSERINTERFACE(GUI):

PythonoffersmultipleoptionsfordevelopingGUI(GraphicalUserInterface).OutofalltheGUImeth- ods,
tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit
shipped with Python. Python with tkinter is the fastest and easiest way to create the GUI applications.
Creating a GUI using tkinter is an easy task. To create a tkinter app:
1. Importingthemodule–tkinter
2. Createthemainwindow(container)
3. Addanynumberofwidgets tothe main window
4. Applytheevent Triggeron the widgets.

Importingtkinterissame asimportinganyothermoduleinthePythoncode.Notethatthenameofthe module in


Python 2.x is ‘Tkinter’ and in Python 3.x it is ‘tkinter’.

Importtkinter

TherearetwomainmethodsusedwhichtheuserneedstorememberwhilecreatingthePythonapplica- tion with


GUI.
5. Tk(screenName=None,baseName=None,className=’Tk’,useTk=1):Tocreateamainwindow,
tkinter offers a method ‘Tk(screenName=None, baseName=None, className=’Tk’, useTk=1)’. To
changethenameofthewindow,youcanchangetheclassNametothedesiredone.Thebasiccodeused to create
the main window of the application is:m=tkinter.Tk() where m is the name of the main win- dow
object
6. mainloop(): There is a method known by the name mainloop() is used when your application is
readytorun.mainloop() isaninfiniteloopusedtoruntheapplication,waitforaneventtooccurand process
the event as long as the window is not closed.m.mainloop()

import tkinter
m=tkinter.Tk()
'''
widgetsareadded
here
'''
m.mainloop()
LABORATORY:SIGNAL PROCESSINGLAB 64
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

tkinteralsooffersaccesstothegeometricconfigurationofthewidgetswhichcanorganizethewidgets in the
parent windows. There are mainly three geometry manager classes class.
• •pack()method:Itorganizesthewidgetsinblocksbeforeplacingintheparentwidget.
• •grid()method:Itorganizesthewidgetsingrid(table-likestructure)beforeplacinginthepar- ent
widget.
• •place()method:Itorganizesthewidgetsbyplacingthemonspecificpositionsdirectedbythe
programmer.

Thereareanumberofwidgetswhichyoucanputinyourtkinterapplication.Someofthemajorwidg- ets are


explained below:

▪ Button:Toaddabuttoninyourapplication,thiswidgetisused.Thegeneralsyntaxis:w=Button(mas- ter,
option=value)

master is the parameter used to represent the parent window. There are number of options which are
usedtochangetheformatoftheButtons.Numberofoptionscanbepassed asparametersseparatedby commas.
Some of them are listed below.
➢ activebackground:tosetthebackgroundcolorwhenbuttonisunderthecursor.
➢ activeforeground:tosettheforegroundcolorwhenbuttonisunderthecursor.
➢ bg:tosetthenormalbackgroundcolor.
➢ command:tocalla function.
➢ font:to setthefont onthebuttonlabel.
➢ image:toset theimageonthebutton.
➢ width: to set thewidthof thebutton.
➢ height:to set theheight of thebutton.

▪ Canvas:Itisusedtodrawpicturesandothercomplexlayoutlikegraphics,textandwidgets.Thegen- eral
syntax is:w = Canvas(master, option=value) master is the parameter used to represent the parent
window.
Therearenumberofoptionswhichareusedtochangetheformatofthewidget.Numberofoptionscan be passed
as parameters separated by commas. Some of them are listed below.
➢ bd:toset theborderwidthin pixels.
➢ bg:tosetthenormalbackgroundcolor.
➢ cursor:tosetthecursorusedinthecanvas.
➢ highlightcolor:toset thecolor shownin thefocus highlight.
➢ width: to set thewidthofthewidget.
➢ height:to set theheight of thewidget.

▪ CheckButton:Toselectanynumberofoptionsbydisplayinganumberofoptionstoauserastoggle buttons.
The general syntax is:w = CheckButton(master, option=value)

Therearenumberofoptionswhichareusedtochangetheformatofthiswidget.Numberofoptionscan be passed
as parameters separated by commas. Some of them are listed below.

LABORATORY:SIGNAL PROCESSINGLAB 65
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

 Title:Toset thetitleofthewidget.
 activebackground:tosetthebackgroundcolorwhenwidgetisunderthe cursor.
 activeforeground:tosettheforegroundcolorwhenwidget isunderthecursor.
 Break
 SecretCode:
 AttachaFile:nd color.
 command:to call afunction.
 font:to setthefont onthebutton label.
 image:toset theimageonthewidget.

▪ Entry: Itisusedtoinputthesinglelinetextentryfromtheuser..Formulti-linetextinput,Text widget is


used. The general syntax is:
w=Entry(master,option=value)
master is the parameter used to represent the parent window. There are number of options which are
usedtochangetheformatofthewidget.Numberofoptionscanbepassed asparametersseparatedby commas.
Some of them are listed below.

 bg:tosetthenormal background color.


 bd:toset theborder widthinpixels.
 cursor:tosetthecursor used.
 command:to call afunction.
 highlightcolor: tosetthecolorshowninthefocus highlight.
 width:to setthe widthof thebutton.
 height:tosetthe heightofthebutton.

▪ RadioButton:Itisusedtooffermulti-choiceoptiontotheuser.Itoffersseveraloptionstotheuserand the user


has to choose one option. The general syntax is: w = Radio Button(master,
option=value)Therearenumberofoptionswhichareusedtochangetheformatofthiswidget.Numberofoptions
can be passed as parameters separated by commas. Some of them are listed below.

 Activebackground:tosetthebackgroundcolorwhenwidgetisunderthe cursor.
 Activeforeground:tosettheforegroundcolorwhenwidgetisunderthe cursor.
 bg:tosetthenormal backgroundcolor.
 command:to call afunction.
 font:to setthefont onthebutton label.
 image:toset theimageonthewidget.
 width:to set thewidthofthelabel in characters.
 height:toset theheightofthelabelin characters.

LABORATORY:SIGNAL PROCESSINGLAB 66
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

#WAPtodisplayFramesinPythonusingTkinter.
from tkinter import*
top.geometry("300x200")
tframe=Frame(top,width="100",height="100",bg="yellow")
tframe.pack()
lframe=Frame(top,width="100",height="100",bg="red")
lframe.pack(side=LEFT)
rframe=Frame(top,width="100",height="100",bg="green")
rframe.pack(side=RIGHT)
btn1=Button(tframe,text="SUBMIT",fg="red")
btn1.place(x=10,y=10)
top.mainloop()

OUTPUT:-

#WAPtodisplayMessagebox&buttoninPythonusingTkinter

fromtkinterimport*
fromtkinterimportmessagebox
top=Tk()
top.title("Freakin Hell")
top.geometry("300x200")
def nun():
messagebox.showinfo("Hey man!","You are getting smart enough !")
b1=Button(top,text="Green",bg="green",fg="white",width=10,height=5,activebackground="yellow")
b1.pack(side=LEFT)
b2=Button(top,text="Red",bg="yellow",fg="pink",width=10,height=5,activebackground="yellow")
b2.pack(side=TOP)
b3=Buton(top,text="Blue",bg="blue",fg="white",width=10,height=5,padx=10,pady=5,command=nun)

LABORATORY:SIGNAL PROCESSINGLAB 67
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

b3.pack(side=BOTTOM)
top.mainloop()

OUTPUT:

#WAPtodisplayListboxinPythonusingTkinter.

fromtkinterimport*
top = Tk()
top.title("Fedupofthis!")
top.geometry("300x200")
lbl1=Label(top,text="LISTOFCOLOURS",fg="red",bg="yellow")
lbl1.place(x=10, y=10)
lb=Listbox(top,height=5)
lb.insert(1, "red")
lb.insert(2,"yellow")
lb.insert(3, "green")
lb.insert(4, "blue")
lb.insert(5, "brown")
lb.place(x=10, y=30)
lbl2=Label(top,text="LISTOFFRUITS",fg="blue",bg="green")
lbl2.place(x=160, y=10)
lb1 = Listbox(top, height=5)
lb1.insert(1, "MANGO")
lb1.insert(2, "APPLE")
lb1.insert(3, "BANANA")
lb1.insert(4, "GRAPE")
lb1.insert(5,"STRAWBERRY")
lb1.place(x=160, y=30)
top.mainloop()
LABORATORY:SIGNAL PROCESSINGLAB 68
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

OUTPUT:-

Conculsion:-StudieddifferenttypesofprogrambasedonTkinter.

LABORATORY:SIGNAL PROCESSINGLAB 69
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

EXPERIMENTNUMBER 10

ImplementtheconceptofDataBasein PythonusingSQLite
EXPERIMENTNAME
 WAPtocreateand insertdatainformoftablein aDatabase .

DATE OF
PERFORMANCE

DATEOFCORRECTION

SIGN&DATE

GRADE

TIMELY LAB
ATTENDANCE CORRECTION PERFORMANCE ORAL TOTA
L

ALLOTTED 2 2 3 3 10

OBTAINED

LABORATORY:SIGNAL PROCESSINGLAB 70
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

EXPERIMENT10

AIMOFEXPERIMENT: Implementtheconcept DataBaseinPython usingSQLite


 WAPtocreateandinsert datainformoftablein aDatabase .

SOFTWARE/EQUIPMENT:PC,PythonIDLE.

THEORY:

 PythonSQLite3:
PythonSQLite3moduleisusedtointegratetheSQLitedatabasewithPython.ItisastandardizedPython DBI
API 2.0 and provides a straightforward and simple-to-use interface for interacting with SQLite
databases.ThereisnoneedtoinstallthismoduleseparatelyasitcomesalongwithPythonafterthe 2.5x version.
This Python SQLite tutorial will help to learn how to use SQLite3 with Python from basics to advance
with the help of good and well-explained examples and also contains Exercises for honing your skills.
 ConnectingtotheDatabase:

ConnectingtotheSQLiteDatabasecanbeestablishedusingtheconnect() method,passingthenameof the


database to be accessed as a parameter. If that database does not exist, then it’ll be created.
Syntax:
sqliteConnection=sqlite3.connect('sql.db')
Butwhatifyouwanttoexecutesomequeriesaftertheconnectionisbeingmade.Forthat,acursorhas to be
created using the cursor() method on the connection instance, which will execute our SQL queries.
Syntax:
cursor=sqliteConnection.cursor()
print('DB Init')

 CreateaTable
FollowingPythonprogramwillbeusedtocreateatableinthepreviouslycreateddatabase. #!/usr/bin/python
import sqlite3

LABORATORY:SIGNAL PROCESSINGLAB 71
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

conn=sqlite3.connect(‘test.db’)
print"Databaseopenedsuccessfully!”
imconn.execute('''CREATETABLECOMPANY
(ID INT PRIMARY KEYNOT NULL,
NAME TEXTNOT NULL,
AGE INT NOTNULL,
ADDRESS CHAR(50),
SALARY REAL);''')
print"Tablecreated successfully";

conn.close()
Whentheaboveprogramisexecuted,itwillcreatetheCOMPANYtableinyourtest.dbanditwill display the
following messages −
Openeddatabasesuccessfully
Table created successfully

 INSERTOperation
FollowingPythonprogramshowshowtocreaterecordsintheCOMPANYtablecreatedintheabove example.
#!/usr/bin/python

import sqlite3

conn=sqlite3.connect('test.db')
print"Openeddatabasesuccessfully";

conn.execute("INSERTINTOCOMPANY(ID,NAME,AGE,ADDRESS,SALARY)\ VALUES
(1, 'Paul', 32, 'California', 20000.00 )");

conn.execute("INSERTINTOCOMPANY(ID,NAME,AGE,ADDRESS,SALARY)\ VALUES
(2, 'Allen', 25, 'Texas', 15000.00 )");

conn.execute("INSERTINTOCOMPANY(ID,NAME,AGE,ADDRESS,SALARY)\ VALUES
(3, 'Teddy', 23, 'Norway', 20000.00 )");

conn.execute("INSERTINTOCOMPANY(ID,NAME,AGE,ADDRESS,SALARY)\ VALUES
(4, 'Mark', 25, 'Rich-Mond ', 65000.00 )");

conn.commit()

LABORATORY:SIGNAL PROCESSINGLAB 72
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

print"Recordscreatedsuccessfully";
conn.close()
Whentheaboveprogram is executed,itwillcreatethegivenrecordsintheCOMPANYtableandit
willdisplay thefollowing twolines−
Openeddatabasesuccessfully
Recordscreated successfully

#WAPtocreateandinsertdataintableby
usingsqlite.

importsqlite3
conn=sqlite3.connect("test.db")
conn.execute('''CREATETABLESTUDENTINFO
(IDINTPRIMARYKEY NOTNULL,
NAMETEXT NOTNULL,
AGEINT NOTNULL,
BRANCHTEXT NOTNULL,
DIVTEXT);''')
conn.execute("INSERTINTOSTUDENTINFO
ID,NAME,AGE,BRANCH,DIV)”
“VALUES(401,'ROBERT
BARATHEON',45,'EXTC','A')";
conn.execute("INSERTINTOSTUDENTINFO(ID,NAME,AGE,BRANCH,DIV)"
"VALUES(402,'TRYIONLANNISTER',40,'EXTC','A')");
conn.execute("INSERTINTOSTUDENTINFO(ID,NAME,AGE,BRANCH,DIV)"
"VALUES(403,'JONSNOW',30,'EXTC','A')");
conn.execute("INSERTINTOSTUDENTINFO(ID,NAME,AGE,BRANCH,DIV)"
"VALUES(404,'BRANKSTARK',19,'EXTC','A')");
conn.execute("INSERT INTOSTUDENTINFO (ID,NAME,AGE,BRANCH,DIV)"
"VALUES(405,'ROBBSTARK',25,'EXTC','A')");
cursor=conn.execute("SELECTID,NAME,AGE,BRANCH,DIVFROMSTUDENTINFO")
forrowincursor:
print("ID:",row[0])
print("NAME:",row[1])
print("AGE:",row[2])
print("BRANCH:",row[3])
print("DIV:",row[4],"\n")
conn.commit()
print("Recordscreatedsuccessfully");
LABORATORY:SIGNAL PROCESSINGLAB 73
conn.close()
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

OUTPUT:-

Conculsion:-StudiedDatabaseinPython.

LABORATORY:SIGNAL PROCESSINGLAB 74
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

EXPERIMENTNUMBER 11

WriteaPythonprogramtounderstandandimplementArraysinPython using
EXPERIMENTNAME Numpy (Numerical Python).

DATE OF
PERFORMANCE

DATEOFCORRECTION

SIGN&DATE

GRADE

TIMELY LAB
ATTENDANCE CORRECTION PERFORMANCE ORAL TOTAL

ALLOTTED 2 2 3 3 10

OBTAINED

LABORATORY:SIGNAL PROCESSINGLAB 75
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

EXPERIMENT11

AIMOFEXPERIMENT:WriteaPythonprogramtounderstandandimplementArraysinPython using
Numpy (Numerical Python)

SOFTWARE/EQUIPMENT:PC,PythonIDLE.

THEORY:

 NumPyarray inPython:
Pythonlistsareasubstituteforarrays,buttheyfailtodelivertheperformancerequiredwhilecomputing large
sets of numerical data. To address this issue we use a python library called NumPy. The word NumPy
stands for Numerical Python.

 Unlikelists,NumPyarraysareoffixedsize,andchangingthesizeofanarraywillleadtothe creation
of a new array while the original array will be deleted.
 Alltheelements inan arrayareof thesametype.
 Numpyarraysarefaster,moreefficient,andrequireless syntaxthanstandardpython sequences.
 Numpyarrayfroma list
Youcanusethenpaliastocreatendarrayofalistusingthearray() method.
li =[1,2,3,4]
numpyArr=np.array(li)

or
numpyArr=np.array([1,2,3,4])

Thelistispassed tothearray() methodwhichthenreturns aNumPyarray withthesameelements.

 CreationofarraysusingNumpy:
Creationof1-Darray:
import numpy as np

arr=np.array([1,2,3,4,5])

print(arr)

LABORATORY:SIGNAL PROCESSINGLAB 76
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

Creationof2-D array:
importnumpyas np

arr=np.array([[1,2,3],[4,5,6]])

print(arr)
Creationof3-D array:
importnumpyas np

arr=np.array([[[1,2,3],[4, 5,6]],[[1,2, 3],[4, 5,6]]])

print(arr)
 ArrayIndexing:Knowingthebasicsofarrayindexingisimportantforanalysingandmanipu- lating
the array object. NumPy offers many ways to do array indexing.

 Slicing:Justlikelistsinpython,NumPyarrayscanbesliced.Asarrayscan bemultidimen- sional,


you need to specify a slice for each dimension of the array.
#WAPtoperformmathematicaloperationson1-D,2-d&3-DarrayusingNumpy

import numpy as np
#Operationson1-Darray
a=np.array([500,200,300])
print(type(a))
print(a)
b=[10,20,30]
x=np.array(b)
print(type(x))
print(x)
print(a-x)
print(a+x)
print(a*x)
print(a/x)
print(a.shape)
print(a[0],x[2])
#Operationson2-Darray
c=np.array([[1,2,3,4],[5,6,7,8]])

LABORATORY:SIGNAL PROCESSINGLAB 77
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

d=np.array([[4,3,2,1],[8,7,6,5]])
print(c)
print(d)
print(c+d)
print(c*d)
print(c/d)
print(c.shape)
print(d[0,0],c[0,3])
print(d[0:3,0:3])
#Operationson3-Darray
p=np.array([[[69,96,66,88],[13,14,15,16],[8,9,10,11]]])
q=np.array([[[45,65,32,11],[12,43,56,74],[5,9,4,2]]])
print(q)
print(p-q)
print(q+p)
print(p*q)
print(p/q)

Output:-

LABORATORY:SIGNAL PROCESSINGLAB 78
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

Conculsion:-ImplenteddifferentprogramusingNumpy.

LABORATORY:SIGNAL PROCESSINGLAB 79
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

EXPERIMENTNUMBER 12

EXPERIMENTNAME DesignaDataFrametounderstandmerging,joining,andconcatenation in
Pandas.

DATE OF
PERFORMANCE

DATEOFCORRECTION

SIGN&DATE

GRADE

TIMELY LAB
ATTENDANCE CORRECTION PERFORMANCE ORAL TOTAL

ALLOTTED 2 2 3 3 10

OBTAINED

LABORATORY:SIGNAL PROCESSINGLAB 80
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

EXPERIMENT12

AIMOFEXPERIMENT:DesignaDataFrametounderstandmerging,joining,andconcatenationin Pandas.
EQUIPMENT/SOFTWARE:PC,PythonIDLE.

THEORY:

PANDAS:PandasisaPythonpackageprovidingfast,flexible,and expressivedatastructuresdesigned
tomakeworkingwith“relational”or“labeled”databotheasyandintuitive.Itaimstobethefundamen- tal high-
level building block for doing practical, real-world data analysis in Python.

 Pandasisanopen-sourcelibrarythatismademainlyforworkingwithrelationalorla-
beleddata both easily and intuitively.
 Itprovidesvariousdatastructuresandoperationsformanipulatingnumericaldataand
timeseries.
 PandasbuildsonpackageslikeNumpy&matplotlibtogiveusasingleandconvenient place
for data analysis and visualization.
 Pandasisfastandit hashighperformance&productivityforusers.
FEATURESOFPANDAS:
 Fastandefficientformanipulatingandanalyzingdata.
 Datafromdifferentfileobjectscanbeloaded.
 Easyhandlingofmissingdata(representedasNaN)infloatingpointaswellasnon-floating point
data
 Sizemutability:columnscanbeinsertedanddeletedfromDataFrameandhigherdimensional
objects
 Datasetmergingandjoining.
 Flexiblereshapingandpivotingofdatasets
 Dataalignment&integratedhandlingofmissingdata
 Label-basedslicing&indexing.
 Providestime-seriesfunctionality.
 Powerfulgroupbyfunctionalityforperformingsplit-apply-combineoperationsondatasets.

Pandasgenerallyprovidetwodatastructuresformanipulatingdata,Theyare:
• Series
• DataFrame
• Series:
PandasSeriesisaone-dimensionallabeledarraycapableofholdingdataofanytype(integer,string, float,
python objects, etc.)i.e. Homogenous data.
• Theaxislabelsarecollectivelycalledindexes.
• PandasSeriesisnothingbutacolumninanexcelsheet.Labelsneednotbeuniquebutmust be a
hashable type.

LABORATORY:SIGNAL PROCESSINGLAB 81
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

• Theobjectsupportsbothintegerandlabel-basedindexingandprovidesahostofmethodsfor
performing operations involving the index.
• PandasseriesSizeisimmutableanddataisimmutable

Syntax:
pandas.Series(data,index,datatype,copy)

• Seriescanbecreatedusing:
1. Array
2. Dictionary
3. ScalarValueor Constant.

• DataFrame:
PandasDataFrameisatwo-dimensionalsize-mutable,potentiallyHeterogeneoustabulardatastructure with
labelled axes (rows and columns).
• ADataframeisan-dimensionaldatastructure,i.e.,dataisalignedinatabularfashioninrows and
columns.
• PandasDataFrameconsistsofthreeprincipalcomponents,thedata,rows,andcolumns.
• BasicFeatures:
1.HeterogeneousData.2.Size Mutable.
3. DataMutable.

Syntax:
pandas.DataFrame(data,index,colums,datatype,copy)

• DataFramecanbecreatedwith:
1. List,2.Dictionary,3.Series,4.Numpyndarrays,5.AnotherDataFrame

 SOURCECODE:-

#Writeapythonprogramtostudyandunderstandmerging,joining,andconcatenation in
pandas DataFrame.

import pandas as pd
data1=pd.DataFrame({'id':[1,2,3,4],'name':['manoj','manoja','manoji','manji']},ind
ex=['one','two', 'three','four'])
data2=pd.DataFrame({'s_id':[1,2,3,6,7],'marks':[98,90,78,86,78]},index=['one','tw
o','three', 'siz','seven'])
#Method of joining DataFrames based on indexes.
print("JoinedDataFrameisasfollow:")print(data1.join(data2))

LABORATORY:SIGNAL PROCESSINGLAB 82
(PermanentlyAffiliatedtoUniversityof Mumbai)
DepartmentofElectronicsand TelecommunicationEngineering

#TomergeDataFrameswithMatchingIndexes
print("Merged DataFrame is as follow:")
print(pd.merge(data1,data2,left_index=True,right_index=True))
#To concate the DataFrames print("Concatenation:")
print(pd.concat([data1,data2],axis=1))

OUTPUT:-

Conculsion:-StudiedDataFrameinpython

LABORATORY:SIGNAL PROCESSINGLAB 83

You might also like