Ip Study
Ip Study
Session: 2022-23
Class-XII
INFORMATICS PRACTICES
Data Handling using Pandas-Python Unit-1(25 Marks)
Python Library – Pandas Basic Features of Pandas
• Python package for data • Keep track of our data.
1 or 2
science. • Use of different data types (float, int, string, date time, etc.) Marks
• Builds on packages like • Easy grouping and joins of data
NumPy and matplotlib • Good IO capabilities
• data analysis and • Python MYSQL Connectivity
visualization work. • Label-based slicing, indexing and subsetting of large data sets.
Data Structures in Pandas Two important data structures of pandas are– Series,DataFrame. 1 Mark
Series: It is like a one- Basic feature of series are: 1 Mark
dimensional array like • Homogeneous data
structure with homogeneous • Size Immutable
data. For example, the • Values of Data Mutable
following series is a collection Syntax: - pandas.Series (data, index, dtype, copy)
of integers. Creation of Series is possible from –darray, dictionary & scalar value
Create a Series from ndarray import pandas as p1 Output: 2
import numpy as np1 10 P Marks
data = np1.array(['P','R','E','M']) 11 R
s=p1.Series(data,index= [10,11,12,13]) 12 E
print(s) 13 M
Create a Series from import pandas as pd1 Output 2
dictionary import numpy as np1 b NaN Marks
data = {'P’: 0., 'R’: 1., 'E’: 2.,'M’: 2.} c NaN
s=pd1.Series(data,index=['b','c','d','a']) d NaN
print(s) a NaN
Create a Series from Scalar import pandas as pd1 Output 2
import numpy as np1 05 Marks
s = pd1.Series(5, index= 15
[0, 1, 2, 3]) 25
print(s) 35
Note: - here 5 is repeated for 4 times
Maths operations with Series import pandas as pd1 Output 2
s = pd1.Series([1, 2, 3]) 02 Marks
t = pd1.Series ([1, 2, 4]) 14
u=s+t #addition operation print (u) 27
u=s*t # multiplication operation
print (u) 01
14
2 12
head and tail function: head import pandas as pd1 Output 2
() returns the first n rows s = pd1.Series ([1, 2, 3, 4, 5], index = a1 Marks
(observe the index values) and ['a','b','c','d','e']) b. 2
tail() returns the last n rows print (s.head (3)) c. 3
(observe the index values). print (s.tail (3)) Return first 3 elements
The default number of -----------------------------
elements to display is five. c3
d. 4
e. 5
Return last 3 elements
Accessing Data from Series import pandas as pd1 Output: 2
with indexing and slicing s = pd1.Series ([1, 2, 3, 4, 5], 1 # for 0 index position Marks
index = ['p','r','e','m','e']) 1 #for first 3 index values
print (s[0]) 2
print (s[:3]) 3
print (s[-3:]) 3 # slicing for last 3 index values
4
5
Retrieve Data from selection s = pd.Series (np.nan, index= s.iloc[:3] # slice the first 2
[49, 48,47,46,45, 1, 2, 3, 4, 5]) three rows Marks
49 NaN
48 NaN
47 NaN
DataFrame: It is like a two- Create DataFrame
dimensional array with It can be created with following:
1 or 2
heterogeneous data. • Lists Marks
features of DataFrame are: • Dict
• Heterogeneous data • Series
• Size Mutable • Numpy ndarrays
• Data Mutable • Another DataFrame
Create a DataFrame from import pandas as pd1 Output
Lists data1 = [['Freya',10],['Mohak',12], Name Age 2
Marks
['Dwivedi',13]] 1 Freya 10
df1 = pd1.DataFrame(data1,columns= 2 Mohak 12
['Name','Age']) 3 Dwivedi 13
print (df1)
Create a DataFrame from import pandas as pd1 Output 2
Dict of ndarrays / Lists data1 = {'Name’: ['Freya', Name Age Marks
'Mohak'],'Age':[9,10]} 1 Freya 9
df1 = pd1.DataFrame(data1) 2 Mohak 10
print (df1)
Create a DataFrame from import pandas as pd1 Output 2
List of Dicts data1 = [{'x': 1, 'y': 2}, {'x': 5, 'y': 4, 'z': 5}] x y z Marks
df1 = pd1.DataFrame(data1) 0 1 2 NaN
print (df1) 1 5 4 5.0
Create a DataFrame from import pandas as pd Output 2
Dict of Series d1 = {'one': pd1.Series([1, 2, 3], index= ['a', one two Marks
'b', 'c']), a 1.0 1
'two': pd1.Series([1, 2, 3, 4], index= ['a', 'b', b 2.0 2
'c', 'd'])} c 3.0 3
df1 = pd1.DataFrame(d1) d NaN 4
print (df1)
Column Selection print (df ['one']) 1
Marks
Column addition df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}) 1
c = [7,8,9] Marks
df[‘C'] = c
Adding a new column using df['four’] =df1['one’] +df1['three'] 1
the existing columns values Marks
Column Deletion del df1['one'] # Deleting the first column using DEL function
df.pop('two') #Deleting another column using pop function 1
Marks
Rename columns df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}) Output 2
>>> df.rename(columns= {"A": "a", "B": "c"}) ac Marks
014
125
236
#Selection by Label
import pandas as pd1 Output 2
Marks
d1 = {'one': pd1.Series([1, 2, 3], index= ['a', 'b', one 2.0
'c']), two 2.0
'two’: pd1.Series([1, 2, 3, 4], index= ['a', 'b', 'c', Name: b,
'd'])} df1= pd1.DataFrame(d1) dtype: float64
Row Selection print (df1.loc['b'])
#Selection by integer location 2
import pandas as pd1 Output Marks
d1 = {'one': pd1.Series([1, 2, 3], index= ['a', 'b', one 3.0
'c']), two 3.0
'two': pd1.Series([1, 2, 3, 4], index= ['a', 'b', 'c',
'd'])}
df1 = pd1.DataFrame(d1)
print (df1.iloc[2])
Addition of Rows import pandas as pd1 Output 2
df1 = pd1.DataFrame([[1, 2], [3, 4]], columns = ['a', 'b']) a b Marks
df2 = pd1.DataFrame([[5, 6], [7, 8]], columns = ['a', 'b']) 0 1 2
df1 = df1.append(df2) 1 3 4
print (df1) 0 5 6
1 7 8
Deletion of Rows # Drop rows with label 0 1
df1 = df1.drop(0) Marks
Iterate over rows in a import pandas as pd1 2
DataFrame import numpy as np1 Marks
raw_data1 = {'name': ['freya', 'mohak'],'age': [10, 1],
'favorite_color': ['pink', 'blue'], 'grade': [88, 92]}
df1 = pd1.DataFrame(raw_data1, columns = ['name', 'age',
'favorite_color', 'grade'])
for index, row in df1.iterrows():
print (row["name"], row["age"])
Output
freya 10
mohak 1
Indexing a DataFrame using import pandas as pd Output 2
.loc[ ]: This function selects import numpy as np a -1.340477 Marks
data by the label of the rows df = pd.DataFrame(np.random.randn(8, 4), index b 0.669544
and columns. = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], columns = ['A', 'B', c -0.185628
'C', 'D']) d -0.658744
#select all rows for a specific column e 0.596576
print df.loc[: ,'A'] f -1.167927
g 0.404994
h -0.576133
Accessing a DataFrame with # importing pandas as pd 2
a Boolean index: In order to import pandas as pd Marks
access a dataframe with a # dictionary of lists
boolean index, we have to dict = {'name': [“Mohak", “Freya", “Roshni"],
create a dataframe in which 'degree': ["MBA", "BCA", "M.Tech"],
index of dataframe contains a 'score': [90, 40, 80]}
boolean value that is “True” or # creating a dataframe with boolean index
“False”. df = pd.DataFrame(dict, index = [True, False, True])
# accessing a dataframe using .loc[] function
print(df.loc [True])
Output:
#it will return rows of Mohak and Roshni only (matching true only)
Binary operation over x = pd.DataFrame({0: [1,2,3], Output 2
dataframe with series 1: [4,5,6], 2: [7,8,9] }) 0 1 2 Marks
y = pd.Series([1, 2, 3]) 0 2 5 8
new_x = x.add(y, axis=0) print(new_x) 1 4 7 10
2 6 9 12
Export Pandas DataFrame to import pandas as pd 1 or 2
a CSV File: cars = {'Brand': ['Honda Civic','Toyota Corolla', 'Ford Focus', Marks
'AudiA4'],
to_csv function 'Price': [22000,25000,27000,35000]}
df = pd.DataFrame(cars, columns= ['Brand', 'Price'])
df.to_csv (r'D:\export_dataframe.csv', index = False, header=True)
print (df) #csv file will be created in specified file location with
specified name.
read_csv function: import pandas as pd Output: 1 or 2
data = pd.read_csv("D: Brand Price Marks
\export_ 0 Honda Civic 22000
dataframe.csv") 1 Toyota Corolla 25000
print(data) 2 Ford Focus 27000
3 Audi A4 35000
• Degree: Total No. of Columns in a table is called its Degree. In the above table degree is 4.
• Cardinality: Total No of Rows in a Table is Called its Cardinality. In the above table cardinality is
5. (Note, while calculating cardinality we do not count the header row.)
TIP: Degree →Column (DC : Direct Current ) ; Cardinality → Row (CR : Credit Ratio) Both C not
together
Q . A table has 4 rows and 6 column find its degree and cardinality. [1 or 2 Marks]
Ans. Degree 6 ; Cardinality 4
Q. A table has 6 rows and 5 columns. 2 insert operations are performed on it. Find the new degree and
cardinality of the table? [1 or 2 Marks]
Ans. Degree 5; Cardinality 8
SQL COMMANDS
Data Manipulation Language (DML)
1 INSERT
To add new record or records into a table
INSERT INTO EMP VALUES(101,”RAKESH SHARMA”,’1995-05-10”, ”MANAGER”, ”REGULAR”,
12345678911, 50000, ”SALES”);
2 DELETE
To Remove tuples from a table.
DELETE FROM <tablename> WHERE <Condition>;
DELETE FROM emp WHERE Ename = ’Rakesh Sharma’;
3 UPDATE
To modify or change the data in the tables
UPDATE <tablename>
SET Attribute1=<new value>, Attribute2=<new value>,…
WHERE <Condition>
Update emp set sal = sal = 50 where deptno =30;
4 SELECT [3+2 Marks/Query / Output ]
To view / show / fetch / extract rows or tuples from table(s) or relation(s)
SELECT Attribute list/*
FROM table name(s)
WHERE Condition
ORDER BY Attribute name
GROUP BY Attribute name
HAVING Condition
DISTINCT, AS, AND, OR, NOT, IN / NOT IN, BETWEEN / NOT BETWEEN, IS NULL / IS NOT NULL
5 SINGLE ROW FUNCTIONS
NUMERIC FUNCTIONS – [1 Mark / Output Based]
- POW(X,Y) - x raise to the power of y Select Pow(8,2); → 64
- MOD(X,Y) - Remainder of X/Y Select MOD(80/12) → 8
- ROUND(N,D) - Rounds number N upto given D Select Round(123.7898,2); → 123.79
no. of digits
- SIGN(N) - If N is position then output 1, Select SIGN(-165); → -1
negative then -1 and Zero then output is 0 Select SIGN(0) ; → 0
- SQRT(X) – Returns square root of X Select SQRT(144): → 12
SRING/CHARACTER FUNCTIONS [1 Mark / Output Based]
- LENGTH(STR) : Find Number of characters in Select LENGTH(‘APPLE’) → 5
given string.
Introduction to Internet: The Internet is a vast network that connects computers all over the world.
URL : Uniform Resource Locator : address of a given unique resource on the Web.
e.g. http://www.example.com/index.html
Domain Name: A domain name is the permanent address of a website on the Internet.
e.g. www.yahoo.com
WWW: World Wide Web : also known as a Web, is a collection of websites or web pages stored in web
servers and connected to local computers through the internet.
Web Site: a set of related web pages located under a single domain name, typically produced by a single
person or organization.
Web: is a collection of websites or web pages stored in web servers and connected to local computers
through the internet.
Email: is an Internet service that allows people who have an e-mail address (accounts) to send and receive
electronic letters. These letters may be plain text, hypertext or images. We can also send files with email
using attachments.
Chat : is a way of communication, in which a user sends text messages through Internet. The messages can
be send as one to one communication (one sender sending message to only one receiver) or as one to
many communication (one sender sending a message to a group of people)
VoIP: Voice over Internet Protocol: is a technology that allows you to make voice calls using an Internet
connection instead of a regular (or analog) phone line.
Difference between a Website and webpage
Webpage Website
Webpage is a single document on the Internet Website is a collection of multiple webpages with
information on a related topic
Each webpage has a unique URL. Each website has a unique Domain Name
Static Web Page: A static web page (sometimes called a flat page or a stationary page) is a web page that is
delivered to the user's web browser exactly as stored. i.e. static Web pages contain the same prebuilt content
each time the page is loaded
Dynamic web page: The contents of Dynamic web page are constructed with the help of a program. They may
change each time a user visit the page. Example a webpage showing score of a Live Cricket Match.
Web Server: Web server is a computer where the web content is stored. Basically web server is used to host
the web sites
Hosting of a Website: When a hosting provider allocates space on a web server for a website to store its files,
they are hosting a website. Web hosting makes the files that comprise a website (code, images, etc.) available
for viewing online
Web Browser: A web browser (commonly referred to as a browser) is a software application for accessing
information on the World Wide Web. e.g. Internet Explorer, Google Chrome, Mozilla Firefox, and Apple Safari.
Add-ons/plug-ins : is a software component that adds a specific feature to an existing computer program.
Cookies: are combination of data and short codes, which help in viewing a webpage properly in an easy and fast
way. Cookies are downloaded into our system, when we first open a site using cookies and then they are stored
in our computer only. Next time when we visit the website, instead of downloading the cookies, locally stored
cookies are used. Though cookies are very helpful but they can be dangerous, if miss-utilized.
Protocols: Protocols are set of rules, which governs a Network communication. Or set of rules that determine
how data is transmitted between different devices in a network.
HTTP : Hyper Text Transfer Protocol : HTTP offers set of rules and standards which govern how any
information can be transmitted on the World Wide Web
HTTPs : Hypertext Transfer Protocol Secure: It is advanced and secure version of HTTP.
TCP/IP : Transmission Control Protocol / Internet Protocol : determine how a specific computer should be
connected to the internet and how data should be transmitted between them.
FTP : File Transfer Protocol : Transfer file(Upload/ Download) files to or from a remote server.
SMTP : Simple Mail Transfer Protocol : purpose is to send, receive, mail between email senders and
receivers.
POP3 : Post Office Protocol version 3 : standard protocol for receiving e-mail.
VoIP : Voice Over Internet Protocol :
HTTP HTTPs
HTTP is unsecured HTTPS is secured
HTTP sends data over port 80 HTTPS uses port 443
Hints to solve Case Study based Question: [5 Marks Generally last ques. in QP]
Question Type Hint Answer
Circuit Diagram Connects all the units in the question with a unit having
maximum no. of computers
Best Place to host Server Unit having Maximum no. of computers
Placing of Switch/Hub In each unit
Placing of Repeater Between units where distance is more than 100m
Most economical Communication Broadband
medium
Communication media for small Ethernet Cable
Distance < 100 m
Communication Media for Radio Waves,
Desert areas
Communication Media for Hilly Radio Waves/ Microwaves
Areas
Hardware/Software to prevent Firewall
unauthorized access
Societal Impacts
Weightage: Part-A Section – I [5 Questions of 1 mark each (Fill in the blank/True False)] =5 Marks
Part-B Section – I [2 Questions of 2 Marks] and [Section – II 1 Question of 3 Marks]= 7 Marks
1. Digital Footprint is the trace you leave on the internet.
Ex. online purchase using your device, Check your insta feed and like a post.
Types: Active (A video uploaded on reels) & Passive (Window shopping on amazon).
How to reduce the footprint?
Logout after you’re done surfing a Keep comments/likes to a minimum
website
Think before posting on a public platform don’t post too much personal info online
No copyright Share the Respect Respect Avoid cyber Don’t feed the
violation expertise privacy diversity bullying troll
Communication Etiquettes
Be Precise Be Polite Be Credible
Social Media Etiquettes
Be Secure Be Reliable
Choose a strong Know who beware of Think before you upload
password you befriend fake info
3. Intellectual property rights (IPR) allow its owners to exclude/include some third parties in order to
grant permission to access/modify his/her work through licensing while retaining ownership.
licensing of intellectual property: Technology Transfer, Trademark, Copyright and Patent
4. Plagiarism is the act of using or passing off someone else’s work as your own without giving proper
credit to the original creator.
crime or not: Under normal circumstances, it is considered a morally unethical issue but not a crime.
If a copyrighted work is copied without permission then it becomes a crime.
How to detect: Blockchain technology can be used to counter plagiarism. Services like Turnitin and
Grammarly are already used in academia to detect plagiarism.
One has to explicitly choose, or create, the license. It exists, without me doing anything to assert it,
It does not apply automatically. from the moment of creation.
legal term to describe the terms under which Copyright is the legal term used to declare and
people are allowed to use the copyrighted material. prove who owns the intellectual property
Ex. When you are given a licence of the book from Ex. When you buy a book, you’re buying the
the copyright owner. You may republish or sell it printing copy of the book. You’re not buying the
under your name. copyright in the book.
Rootkit: Can’t be removed Trojan Horse: looks like useful Adware: unwanted software that
very easily from within the os software but contains malware bombards advertisements
8. Cyber Law: “law governing cyberspace”. It includes freedom of expression, access to and usage of the
internet, and online privacy. The issues addressed by cyber law include cybercrime, e-commerce, IPR,
Data Protection.
Indian IT Act, 2000 and amendment in 2008 is the cyber law of India.
● Guidelines on the processing, storage and transmission of sensitive information
● Cyber cells in police stations where one can report any cybercrime
● Penalties Compensation and Adjudication via cyber tribunals
9. E-waste: Various forms of electric and electronic equipment that have ceased to be of value to their
users or no longer satisfy their original purpose. Include TV, headphone, cell phone etc.
Hazards: It consists of a mixture of hazardous inorganic and organic materials.
● If mixed with water and soil creates a threat to the environment.
● Burning/Acid bath creates hazardous compounds in the air we breathe.
Management: Sell back, gift/donate, reuse the parts, giveaway to a certified e-waste recycler.
10. Technology and Health:
- Health apps and gadgets to monitor and alert. - Physical: Eye strain, Muscle Problems. Sleep
- Virtual Doctor issues, Depression etc
- VR games to improve fitness in a fun manner - Social: emotional issues, isolation, anti-social
- Online medical records.
behaviour etc