Working with CSV Files and Data Structures
Working with CSV Files and Data Structures
l
Tree craph
DEModule
O Stack
G ' ln computer science, a stack is an abstract data type and a linear or user-defined data structure based on
the principle of Last ln Flrst Out (L|FO).
G . A stack is a list where insertion and deletion can take place only at one end called Top.
. Some basic terms are given below
t.. G Terms
Peek
Delinition
Reter to the inspecting the value at the stack,s top without moving it. tt is ais;
sometimes referred as inspection.
? a Stack Top
Stack Push
Points at the top most position or point to the last item in stack.
The procedure of inserting a new element to the top of the stack is known as push
ne, operalion.
] Stack Overflow Any attempt to insert a new element in already full stack results shows overflow.
Stack Pop The procedure of removing element from the top of the stack is ca eO Fop opention
Xiac!!!!g!!9y
,"6 ofe Applicatians of Stack
Any attempt to detete an etement from atready empryitacX resutrs as LrnOe*ror,,r
o 6
Computer Network
O A computer network is a system oI interconnected computers and devices that communicate with each other
to share data, software, and hardware resources.
O O Types of Networks
1. Local Area Network (LAN) A network in which computers and devices are connected over a relatively short
o distance, usually within a single building or campus (up to a few kilometres). LANs are generally privately
owned.
2. Metropolltan Area Network (MAN) A larger version of a LAN, covering an area ranging rrom s km to 50 km,
o such as a city. MANS can be private or public and often connect multiple LANS.
3. Wide Area Network (WAN) A network that spans a large geographical area (country or continent) and uses
Network Devices
Hardware device that are used to connect computers, printers, tax machines and other electronic devices to a
C network are called network device.
Devlce Function
o|. Hub
weak and retransmits them over long distances.
Central device that connects sends data to all connected devices.
S'ititch Connects devices and sends data onlv to lhe intended more efiicient than a hub.
Gateway Connects d,fferent networks with different protocols; translates data between systems (e.g., LAN e,
Tansmiss
Transmissk
.E@ Data Communication
:ata- is the process ot exchanging digital
_communicalion
:evices informati,
lt involves a sender transmrttrng between two or more computing
samunication medium (wired a message (rite text, imao]l or
or wiretess). -es, video) to a receiver through a
?-._Components of Data Gommunication
uara communication requires
the following essential components:
Component Explanation
Message rh::i!gl!gE t" b"len"rit JGrt,
Sender audio, video, etc.)
Receiver
Transmission l\,ledia
Protocol
O"",ot","nO"rO r,""ffi
!11:ur,.r..n of Communication Media
Bandwidth ""lu",r,
rt is fhe maximum data transfer
capacity of a communication
ditference between ttre trighest chann, measured in bps or Mbps. lt
ani rowest frequencies of th" "l' is the
Example A .lOO
Mbps link can transfer 1OO
milion bit. p", "h"rn"l.
Data Transfet Rate (Speed) """ona.
is transmitted over a [Link]
) pages, that I::#J*Tr.:ffi"::r-Ji'[:"" is usua,y tess than bandwidrh
and is
/P Address
(lnternet Protocol Address)
inks is called l"J:#:[:t is a unique numericar identifier
assigned to each device conneded
Tylr-s of lp Address
Bits
:senting and Bgmarka
lPv4 32-bit [Link]
gle Chrome. lPv6
Common, but limited
128-b Z0O'l :0db8:BSaS:O0OOOOOO:
. Used to identify sender and
receiver in data transmission.
Newer version, more devices
Trcnsmission Media
3 Transmission media are the paths
through which data is transmitted
trom one point to another.
A. Wircd (Cuided) Media QDa
Type Descriplion A Datal
Twisted Pair Cable Two insulated copper wires twisted together; used in LANS. lnexpensive. databas
Co-axial Cabl€ lt has a contral core conductor; used for cable TV and data transmission.
Fiber Optic Cable lt uses light to transmit data. High bandwidth and long distance O vie
communication. The ma
Lr Logical
PPP Direct link b6tw6en two network nodes.
It is the r
TELNET Remote loqin (insecure). can say t
Voice/video over lnternet. C applicatic
Each relati(
1 . Equi Jain
Equi join is a simple SQL join condition .that uses
c- Syntax SILtCT col1, col2, col3
equal sign as a comparison operator.
2. Self Join
o- .A selfjoin is a join, where we join a particular
table to itself.
HeIe in this case, it is necessary to ensure that the join
statement defines an ALIAS name for both the copies
ol the tables to avoid column ambiguity
o- 3. Non-Equi Join
Non-equi join is used to return the resurt from two
or mors tabres, where exact join is not possibre.
c- join uses comparison oparators instead of,
the €quat sign like >,<,>=,<= alongwirh
]j;O,r,ifll. "".-"Ori
.. 4. Natural Join
The natural join is a type of equi join and is structured
in such a way that, columns with same name of
associated tables will appear once only.
.-
:10
a
.'.
lnterface Python with SQL
? a while developing real life
situation where
applications,
we need to connect it with database in order to encounter
such
the data stored
in database need
to be ,"niprr"i"ol"n"nged. python arows to us connect
O a our application to the databasss like MySeL,MongoOg,
SOf_ite ana many others.
I python
Connecting to MySeL
user can wJite-Python script using [Link] library,
after instafling python MysQL connector. lt can
] connect to MySQL databases python.
,rom
I nstal I mysq [Link] necto r
al To connect the Python application with MysQL
program. The [Link] is not a buird-in
database, we must import the [Link] module in
the
to install it using pip installer.
modure, we need to insta[ it. Execuie the lolo*irg.;r;"ro
)t)!tt\J\ -r
Dt p I lSta I I mysql _connector
If you are using Anaconda Jupyter then type Iollowing
command on terminal
O
conda i nstal I
c anaconda mysql _connector,pythor
Creating Cursor Obiect
The cursor object allows execution o, SeL statements.
cursor: con. cursor ( )
Performing lnsert, Update, Delete eueries Using
Cursor
(a) lnsefi Query
lnserts data into a table:
query = 'INSERT INTo student (roll, name, marks) VALUES (ils, ils, %s),,
data = (101, ,,Ravi',, 95)
t
cursor. execute ( query, data )
[Link]
(b) Update Query
Updates existing records:
query: "llpDATE student SET marks = Zs IHERE rolt _ Zs" Gl
data = ( 98, 101)
[Link](query, data)
[Link]
Gl
(c) Delete Query
Deletes records from a table: o{
query: "DELETE FRotv1 student l,tHERE rol.t : Zs,
data - (101,
cL rso r. execu le
)
{ query, data )
Gl
co'1. corti t( '
commito saves the changes permansnfly to lhe database. Ol
Steps tor Creating Database Connectivity
There are various steps for creating database;onnectivity
Step , lmport [Link] module
as follows o{
Step 2 Create the connection object
Step 3 Creating the cursor obieet
o{
Step 4 Execute the query
Step SClean up the environment }{
!Operation
D a7:_" o p n i:f , rlvt h9!
" ",
Purpose
}{
Command / Method Dosctiptlon
lnsert (Single Add one r€cord to a INSERT INTO + %s Use '/.s as placeholderfor values.
Record)
lnsert (Multiple
table
Add multiplo rows at
ot
executemany0 + %s Executos multiple inssrt statements
Records) once
elficienily.
Update Modify existing UPDATE Table SEI Used to update one or more fields in a Ol
recgrds column=value WHERE r€cord.
condition
Delete Remove r€cords trom
tabl€
DELETE FROM Table Deletes matching records from the ot
WHERE condition tabls.
Flead - tetchoneo Fetch 1 row fetchone0 Betums next row as a luple, or None it
no row. O
Read - Fetch specifjc fetchmany(size) Hetums next sizs rows as list of tuples.
tetchmany(size) number of rows
Read - fetchall0 Fetch all rows letchall0 Fletums all remaining rows as list ot
o
tuples.