Line By Line 12 IP
Line By Line 12 IP
Pandas Intro:
What is Pandas?
Pandas is a Python library used for data analysis and manipulation.
Use of Pandas
It helps in handling and analyzing structured data efficiently.
Who made Pandas?
Pandas was created by Wes McKinney in 2008.
Main Data Structures
Pandas has two main structures: Series (1D) and DataFrame (2D).
Why use Pandas?
It provides powerful tools to clean, filter, and analyze large datasets easily.
Explaining a Library:
• A library is a collection of pre-written code (modules and functions) that helps simplify programming tasks.
• In Python, libraries like Pandas provide ready-to-use tools to handle complex operations, reducing the need
to write code from scratch.
Data Structures in Pandas:
Series DataFrame
Series is a One-Dimensional data structure. DataFrame is a Two-Dimensional data structure.
Series Data (value) is mutable. It means element’s value DataFrame value is also mutable. It means element’s
can be changed whenever required. value can be changed whenever required.
Series size is Immutable (size cannot change) i.e. Size of DataFrame’s size is Mutable (columns can be added or
a series object once created, cannot change. If you removed)
want to add or drop an element, internally a new Series
object will be created.
Series elements must be homogenous. (same data type Pandas DataFrame can be heterogeneous, meaning that
for all values) it can contain columns of different data types. But in
any single column data should be homogenous. When
you insert data of different types into a column, Pandas
may automatically promote the column to a more
general data type, such as ‘object’, to accommodate the
heterogeneous data.
Attribute Description
Series.index Returns the index of the series
Series.values Returns the underlying data as an ndarray
FULL IP LINE By LINE REVISION
Methods in a Series:
• len(s) → Returns total elements
• s.count() → Counts non-null values
• s.head(n) → Shows first n elements (default 5)
• s.tail(n) → Shows last n elements (default 5)
• s.drop(index) → Removes element at given index
Vector Operations:
• Apply operations on entire Series (e.g., s * 2, s + 5)
Arithmetic Operations:
• Supports element-wise +, -, *, / between Series & Scalars/Series
Filtering Data:
• s[s > 10] → Returns values greater than 10
Sorting Data:
• s.sort_values() → Sorts values
• s.sort_index() → Sorts by index
import pandas as pd
#Dict of List
Dict={"Name":["Komal","Shivani","Poonam","Jia","Megha"],
"Marks":[10,11,11,10,12],
"City":["Kota","Delhi","Goa","Pune","Delhi"]}
Df=pd.DataFrame(Dict,index=["RollNo1","RollNo2","RollNo3","RollNo4","RollNo5"])
print(Df)
FULL IP LINE By LINE REVISION
#Dict of Dict
Dict={"Name":{"RollNo1":"Komal","RollNo2":"Shivani","RollNo3":"Poonam","RollNo4":"Jia","RollNo5":"Me
gha"},
Marks":{"RollNo1":10,"RollNo2":11,"RollNo3":11,"RollNo4":12,"RollNo5":14},
"City":{"RollNo1":"Kota","RollNo2":"Delhi","RollNo3":"Goa","RollNo4":"Pune","RollNo5":"Delhi"}}
Df=pd.DataFrame(Dict)
print(Df)
#List of Dict
D1={"Name":"Komal","Marks":10,"City":"Kota"}
D2={"Name":"Shivani","Marks":11,"City":"Delhi"}
D3={"Name":"Poonam","Marks":11,"City":"Goa"}
D4={"Name":"Jia","Marks":12,"City":"Pune"}
D5={"Name":"Megha","Marks":14,"City":"Delhi"}
List=[D1,D2,D3,D4,D5]
Df=pd.DataFrame(List,index=["RollNo1","RollNo2","RollNo3","RollNo4","RollNo5"])
print(Df)
#List of List
List=[[1,2,3,4,5],[5,6,7,8,56],[9,10,11,12,13]]
Df=pd.DataFrame(List)
print(Df)
#Dict of Series
S1=pd.Series(["Komal","Manu","Poonam","Jia"])
S2=pd.Series([10,12,13,14])
Dict={"Name":S1,"Marks":S2}
Df=pd.DataFrame(Dict)
Df.index=["A","B","C","D"]
print(Df)
Attributes
FULL IP LINE By LINE REVISION
import pandas as pd
D={"Name":["Raja","Rani","Komal"],
"Class":["11B","11C","12A"],
"Marks":[31,34,39]}
Df=pd.DataFrame(D)
print(Df.index)
print(Df.columns)
print(Df.axes)
print(Df.size)#Rows *Col
print(Df.dtypes)#Data Type of each columns
print(Df.shape)#(Row,Col)
print(Df.values)
print(Df.empty)
print(Df.ndim)#2
print(Df.T)#rows into col and Col into rows
Head() and tail()
print(Df.head())#by Default 5 Rows From Top
print(Df.head(2))#2 Rows From Top
print(Df.tail())#by Default 5 Rows From Bottom
print(Df.tail(3))#3 rows from bottom
Accessing Data in DataFrame
1. Access Single Column:
o Df["City"]
o Df.City
o Df.loc[:,"City"]
o Df.iloc[:,2]
2. Access Multiple Columns:
o Df[["City", "Name", "Marks"]]
o Df.loc[:, ["City", "Name", "Marks"]]
o Df.iloc[:, [2, 0, 3]]
3. Access Single Row (loc & iloc):
o Df.loc["R1"] (Label-based)
o Df.iloc[0] (Index-based)
4. Access Multiple Rows (loc & iloc):
o Df.loc[["R1", "R3", "R4"]]
o Df.iloc[[0, 2, 3]]
5. Slicing Rows (loc & iloc):
o Df.loc["R1":"R2"] (Includes last)
o Df.iloc[0:2] (Excludes last)
o Df.loc["R1":"R3":2]
o Df.iloc[0:4:2]
6. Access Single Column (loc & iloc):
o Df.loc[:,"Name"]
FULL IP LINE By LINE REVISION
o Df.iloc[:,0]
7. Access Multiple Columns (loc & iloc):
o Df.loc[:, ["Name", "Marks", "City"]]
o Df.iloc[:, [0, 3, 2]]
8. Slicing Columns (loc & iloc):
o Df.loc[:, "Name":"City"] (Includes last)
o Df.iloc[:, 0:3] (Excludes last)
9. Boolean Indexing (Filtering with Condition):
o Df["Marks"] > 97
o Df.Marks > 97
o Df.loc[:, "Marks"] > 97
o Df.iloc[:, 3] > 97
10.Filtering Rows:
o Df[Df["Marks"] > 97]
o Df[Df.Marks > 97]
o Df.loc[[True, False, True, False, False]]
11. Modify a Single Cell Value (loc & iloc)
o Df.loc["R1", "City"] = "op"
o Df.iloc[0, 2] = "topi"
12. Extra loc & iloc Examples:
o Df.loc["R2":"R4", ["Name", "Marks"]]
o Df.iloc[1:4, [0, 3]]
o Df.iloc[[0, 2], [0, 3]]
13. Slicing Without loc & iloc:
o Df[2:4] (Excludes last)
o Df["R2":"R3"] (Includes last)
14. Add New Column
o Df["NewCol"] = 90
o Df["NewCol"] = [90,45,55,44,33]
o Df.loc[:,"NewCol"] = [90,45,55,44,33]
15. Modify a Column
o Df["Marks"] = [90,45,55,44,33]
o Df.Marks = [90,45,55,44,33]
o Df.loc[:,"Marks"] = [90,45,55,44,33]
16. Add New Row (NCERT Method)
o Df.loc["NewRow"] = 90
o Df.loc["NewRow"] = ["Lovejeet","12A","Kanpur",100]
17. Modify a Row
o Df.loc["R2"] = ["Lovejeet","12A","Kanpur",100]
import pandas as pd
Df=pd.read_csv(r"C:\Users\lovej\OneDrive\Desktop\op.csv")
print(Df)
We can load the data from the op.csv file into a DataFrame, using read_csv()
Importing and exporting data between CSV Files and dataFrames imp
Df.to_csv(r"C:\Users\lovej\OneDrive\Desktop\Mo.csv")
" A Comma Separated Value (CSV) file is a text f ile where values are separated
by comma. Each line represents a record (row). Each row consists of one or more f
ields (columns). They can be easily handled through a spreadsheet application."
Count()/max()/min()/sum()imp Pandas 2
FULL IP LINE By LINE REVISION
print(Df.count())
print(Df.count(0))
print(Df.count(axis=0))
print(Df.count(axis='index'))
print(Df.count('index'))
print(Df.count(1))
print(Df.count(axis=1))
print(Df.count(axis='columns'))
print(Df.count('columns'))
1. Line Chart
Basic Structure:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 40]
plt.plot(x, y) # Create line chart
plt.show() # Display the chart
Common Attributes:
• color='red' → Line color
FULL IP LINE By LINE REVISION
42. Primary Key: A column or a set of columns in a table that uniquely identifies each record in
the table.
43. Foreign Key: A column in one table that uniquely identifies a row of another table, creating a
relationship between the two.
45. DDL vs DML: DDL defines structure (CREATE, ALTER,DROP,RENAME), DML manipulates data
(INSERT, UPDATE,SELECT,DELETE).
46. ALTER vs UPDATE: ALTER modifies table structure; UPDATE modifies data.
47. DROP vs DELETE: DROP removes the table; DELETE removes records.
48. LIKE '%a_': % matches any number of characters, _ matches one character.
SQL Commands
49. GROUP BY groups data, used with aggregate functions; HAVING filters groups, WHERE filters
rows.
FROM table_name
GROUP BY column_name;
• GROUP BY is used with aggregate functions (COUNT(), SUM(), AVG(), MAX(), MIN()).
• HAVING is used to filter grouped results.
51. Equi Join: Joins rows with equal values in specified columns.
Numeric Functions:
• POWER(2, 3) → 8 (2³ = 8)
String Functions:
• UCASE('hello') → 'HELLO'
• LCASE('WORLD') → 'world'
• TRIM(' Hello ') → 'Hello' (Removes both leading & trailing spaces)
Date Functions:
FULL IP LINE By LINE REVISION
• DATE('2025-02-25') → '2025-02-25'
• MONTH('2025-02-25') → 2 (February)
• MONTHNAME('2025-02-25') → 'February'
• YEAR('2025-02-25') → 2025
• DAY('2025-02-25') → 25
• DAYNAME('2025-02-25') → 'Tuesday'
Networking
1. ARPANET: The first prototype of the internet developed by the Advanced Research Projects
Agency.
2. NSF: National Science Foundation, an agency promoting science research and education.
3. PAN, LAN, MAN, WAN: Personal, Local, Metropolitan, and Wide Area Networks classify
networks by size.
4. Fiber Optics: Technology for high-speed data transmission using light through glass or plastic
fibers.
Devices
5. Modem: A device that modulates and demodulates signals for internet connectivity.
11. Tree Topology: A hierarchical network combining bus and star topologies.
12. Mesh Topology: Requires n(n-1)/2 connections for fully connecting n nodes.
Web Technologies
16. WWW: World Wide Web, a vast collection of interlinked web pages.
17. Dynamic vs Static Webpages: Dynamic pages update interactively; static pages do not
change.
18. Web Browser: Software to access and display web pages (e.g., Chrome, Firefox).
19. Protocols: Email communication standards like SMTP, POP, and IMAP.
20. Add-ons are typically browser extensions that modify or add new features (e.g., Dark Mode
extension in Chrome).
13. Plugins are external software components that enable specific functionality (e.g., Flash
Player for multimedia content).
14. Cookies – Small data files stored on a user's device by websites to remember preferences
and track activity.
15. VoIP (Voice over Internet Protocol) – Technology that allows voice communication over the
internet instead of traditional phone lines.
FULL IP LINE By LINE REVISION
TECH Queen
https://www.youtube.com/@TECHQueenLovejeetArora
Two-Month Study Plan Class – 12 IP
CSV File
https://www.y
outube.com/wa
8. ADD new columns tch?v=WXrL9x
(A) NCERT me jo ek tarika btaya hai imp
T0GXU&t=253s
(B) Loc se imp
9. ADD new Row [only one method jo NCERT me hai] imp
DataFrame
10. Drop [ Delete Column and row] imp
Creation Trick
11. Rename column and row imp
https://www.y
12. Joining, Merging and Concatenation of
outube.com/wa
DataFrames[NCERT]
tch?v=_j5yi3oc
13. Importing and exporting data between CSV Files and
2b0&t=1390s
dataFrames imp
14. Pandas series Vs numPy ndarray Pandas
15. Count()/max()/min()/sum()imp Pandas 2 DataFrame -
16. Mean()/Median/mode[Extra] max(), min(),
17. PYQs count(), sum()
https://www.y
outube.com/wa
tch?v=LDBvoqz
Vn6Q
Pandas
DataFrame -
Joining,
Merging &
Concatenation
of DataFrames
https://www.y
outube.com/wa
tch?v=SzazZT3
TYfo
SQL 11th FULL NCERT – Class 11th SQL[Chapter 7 and 8]
FULL IP LINE By LINE REVISION
https://www.youtube.com/watch?v=a72zD76OBDc&list=PL1fd5kIddTjly77Wvccd2u
WwPoTwUVAXx&index=3
Multi Row-
https://www.youtube.com/watch?v=o-
RZNquCP4Y&list=PL1fd5kIddTjly77Wvccd2uWwPoTwUVAXx&index=6
23rd Dec – 30th
Dec Group BY
https://www.youtube.com/watch?v=sf4D9fVnRnA&list=PL1fd5kIddTjly77Wvccd2uWwPoTwUV
AXx&index=7
PYQs on Group By
https://www.youtube.com/watch?v=bvDz6QgR_S4&list=PL1fd5kIddTjly77Wvccd2uWwPoTwUV
AXx&index=8
Having
https://www.youtube.com/watch?v=qltvCYScSzA
Where Vs Having
https://www.youtube.com/watch?v=pBM_7Ns4VCs
Joins
https://www.youtube.com/watch?v=qsmNDZazFOI
PYQs-
https://www.youtube.com/watch?v=oSUBnCanXUI
Societal Impact
One Shot – https://www.youtube.com/watch?v=DjDQQU9Qzfw&t=88s
8th Jan - 9th Jan
Full Playlist - https://www.youtube.com/playlist?list=PL1fd5kIddTjlBAblxxl3M9dOtLwDjWDlL
FULL IP LINE By LINE REVISION
https://www.youtube.com/watch?v=moeuO2qfIIo&list=PL1fd5kIddTjlcxztNY7M-NUODYHeTeMGV