0% found this document useful (0 votes)
29 views7 pages

Working with CSV Files and Data Structures

The document provides an overview of various data management concepts, including working with CSV files, data structures, computer networks, and web concepts. It explains how to read from and write to CSV files, describes different types of data structures and networks, and outlines the basics of web technologies and protocols. Additionally, it touches on data communication, transmission media, and database concepts.

Uploaded by

aryanverma8322
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)
29 views7 pages

Working with CSV Files and Data Structures

The document provides an overview of various data management concepts, including working with CSV files, data structures, computer networks, and web concepts. It explains how to read from and write to CSV files, describes different types of data structures and networks, and outlines the basics of web technologies and protocols. Additionally, it touches on data communication, transmission media, and database concepts.

Uploaded by

aryanverma8322
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

lt*&eBlna,yFile O Sta

t pdaling irwolves: . ln con


. Reading all existing records. the pri
. Modifying the dssired rocord. . A stac
. Wdting all records back to the file. . Some

O Working with CSV Files


CSV Iiles are used to store a large number of variables or data. They are incredibly simplilied spreadsheets.
Each lins in a csv lile is a data record.

Open a CSV File


T; work with csv tile, the tirst thing to do is to open it. You can open a tile using openo method with its name.
It is same as a text lile.
Syntax f:open ( Fi I eName, a cces s-mode )
Close a CSY Fire
When you are linished with work in tiles, it must to close the file as soon as possible. To closs a lile, closs0 Applicat
method is used.
Some ap
Syntax F'i I eName. cl os e ( )
1. Proces
Writing to a CSV File 2. Matchi
(a) wrltero Creates a writer object. 3. Conve
(b) writerowo Writes a single row (list) to the CsV file.
(c) writerows0 Writes multiple rows (list of lists).
Example
t,,/ri ter - csv,writer(f)
r,J[[Link](["Name", "ltlarks"]) /l single row Coml
l.,[Link](tt"Anu", 901, I"Aman", 85ll) lf f'lultiple rol,,/s A comput
to share c
Reading hom a CSV File
Use csv.roader0 to create a reader object and read line by line. @ Type
l,,/ith open("[Link]', "r') as f: 1. Locr
reader = csv, reader( f) dist€
for row in reader: ownr
print(row) 2. Mett
such
g. Widr
5 comt

Data Structures O Netw


Hardware
Data structure is a way of storing and organising information in the computer. network at
A data structure is a group of data that have difierent data types which can be accesssd as a unit. Devlce
Types of Data Structure Bepeater
There are two types ot data structure as follows Hub
Data structure Switch
Gateway
Primitiv*danskucture Non-primitivedltastructure
Bridge

Linear Non-linear Router


Modem
,-\ (MOdulak

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

Some applications oI the stack in computer data processing are as follows


O 1. Processing oI method (subprogram) calls
2. Matching of parentheses in expressions.
3. Converting and evaluating arithmetic expressions (e.g. polish notation).
]

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

oL O commercialand private communication lines to connect multiple LANS.

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,

Divides a network inlo to reduce traffic; at Data Link (Layer 2).


Bouter Forwards daia between networks and finds the best path for data lransmission.
Modem converts digital signals to analog (sender) and analog back to digital (receiver) for transmission over
rrr
\.1 ..J
(MOdulator- telephone lines.
DeYice
RJ45
Ethemet Card
Function
A standard connector for Ethernet cables (8 pins) used to connect devices to a wired network.
Hardware that allows a computer to connect to a wired network via an Ethernet cable.
3 tr
Da'
Wi-Fi Card Enables a device to connect to a wiretess network using radio waves.
C o Data
devic(
O Network Topology comrn
The arrangement ol computers and other peripherals tn
network topologies are as fo,lows Oc,
Topology Data c
Descrlption
gus(finear) nttcompuiersandd*icesarecoml"-G@ C a
Ring (Circular) Each node is connected to two neighbours, forming a circle. Data travels in one
_ direction and returns to thg_-ssnqqqtqlqlsrlg i]l
Star All nodes connect to a central hub/switch. The hub *n eiGr broad"ast to all or -
,es.
3
unicast to a
Tree Extension of bus topology, skuctured like an inverted tree. Boot acts as server, and
branches interconnect in hierarchical form.
Mesh Every node is connected direc y to every other node via dedicated tinks. Also called
completely interconnected iopology.
Measu
O Uniform Resource Locator (URL) Bandn
A specific address used to access resources on the internet. It is th€
differen
Example [Link] exampl e. com
Exampl
O Web Concepts Data Tt
Web Page It is the
The backbone oI the world wide web is made up of files or documents called pages or web pages, that measur€
contain inlormation and links to resources both text and multimedia. lt is created using HTML.
lP Addr
Website An IP Ac
A group of related web pages that follow the same theme and are connected together with hyperlinks is called to a netu
a website. A website displays related inlormation on a specific topic. Types o
Web Browser
A web browser (commonly referred to as a browser) is a sottware application for retrieving, presenting and
traversing information resources on the world wide web. The major web browsers are Google chrome,
Firefox, lnternet Explorer, Opera, and Safari.
. Used t(
Web Seruet . Works I
The term web server can refer to either the hardware (the computer) or the software (the computer
application) that helps to deliver web content, accessible through the lnternet. There are many web server Switchin,
software applications including public domain software from NCSA and Apache and commercial packages Switching
from Microsoft, Netscape and others. 1. Circuit
Web Hosting
. A dedic
A web hosting service is a type of lnternet hosting service that allows individuals and organizations to begins.
their website accessible via the World Wide Web. . Data folt
Web hosting can be of lour types as follows: (i) Free Hosling (ii) Virtual (iii) Dedicated
. Exampl(
Hosting (iv) Co-location Hosting 2, Packet
. Messag€
. Each pa(
. Packets i

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

. Works with TCp/lp protocol.


€ computer
web server *titching Technioues
al packages of transmittins data between
devices in a natwork throush
;H.::1:L#fd intermediare nodes.

' communication path is estabrished betwe.n


ms to make
f"j,"r11"* sender and r€ceiver before data
transmission
. Data follows thebam; tixed path
during the entire ssssion.
) Dedicated
. Example Traditional telephone
calls.
t 2. Packet Switchiing
. Message is divided into packets
o, fixed siz6.
r ' Each packet travers independen'y
and may tak6 different routes
. Packets are reassembled
at the receiver,s end.
to reach the dostinaron.

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

B. wircless (Unguided) Medla Several


lnterna
TYpe [Link]
It is the
Radio Waves Ussd for AM/FN, radios, cordless Good for
medium
Microwaves High-frequency waves, used in mobile phones and satellite communications
lnfrared Waves Used lor shod-range communication like TV remotes. Cannot penetrate walls. Concel
- The con
@ Network Protocols or glob6
Network protocols are a set ol rules and standards that govern how data is transmitted, received, and
Externa
interpreted across computer networks. They enable communication between devices, ensuring that data is
It is the
transferred reliably, securely, and in a format that is understood by all parties,
describe
Protocol Purpoae
jTTP __ Access ryg! plgqs E!9!gryPteg): _ 80 O Datr
HrrPs ffiI! €q!t!s].-- The mair
FTP -_--!999trf9tr19! "f
Transler files betwe€n client and server. --443 20, 2! provides
delinition
SI,TP Sends emails from client to server or between servors. 25
Downloads emails lrom server to client deletes lrom Data ind(

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

O WirelesslMobile Telecommunication Technologies Physical


Various wireless/mobile telecommunication technologies are given below It is the a
Generation Description
1G Analog voice calls (1980s).
& Data
Data mo(
2G Digitalcalls, S[,4S (1991).
relationsh
lnternet access, > 200 Kbps.
4G High-speed broadband lnternet, Hietarch
5G , Ultrajast speeds, low latency, loT support. It compris
or more r(
A Electronic Mail ln a hierat
Electronic mail most commonly referred to as E-mail, is a method of exchanging digital messages from
sender to one or more recipients. Modern E-mail operates across the lnternet or other computer networks. Netwotk
ln networl
Electronlc Mail Proiocol A set o, rules (e.g. SMTP, POP3) used lor sending and receiving emails over the
like hierar,
intemet.
arbitrary g
Relation.
E The relatic
A table is i

Database Goncept ? Retar


A database can be detined as a collection ol organised inlormation in such a way that user can retrieve data ln a relatk
quickly. A database has the following properiies related to r
. lt is a collection of relaled data elements represenling real-world information. Relation
. lt is logical, coherent and internally consistent. A relation i

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.

FR0t"l tabt e1, tdbt e2


c- l^jl ERE tabt e1. cot l = tabt e2. cot l;
SQL equijoins are further classilied into two categories

o. (i) lnner Join (ii) Outer Join

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.

You might also like