Now, let's move to the next topic of Data Science Roadmap:
β Python Dictionaries π
Dictionaries are one of the most important data structures in Python, especially in data science and real-world datasets. They store data in keyβvalue pairs.
πΉ 1. What is a Dictionary?
A dictionary stores data in key:value format.
β Example:
Output:
β Uses curly brackets {}
πΉ 2. Access Dictionary Values
Use the key to access values.
Output:
πΉ 3. Add New Elements
Output:
πΉ 4. Modify Values
πΉ 5. Remove Elements
πΉ 6. Important Dictionary Methods
β
β Get Method:
Output:
β Keys Method:
Output:
β Values Method:
Output:
β Items Method:
Output:
πΉ 7. Loop Through Dictionary
Output:
name Rahul
age 22
π― Todayβs Goal
β Understand keyβvalue pairs
β Access dictionary values
β Add or update data
β Loop through dictionary
π Dictionaries are widely used in APIs, JSON data, and machine learning datasets.
Double Tap β₯οΈ For More
β Python Dictionaries π
Dictionaries are one of the most important data structures in Python, especially in data science and real-world datasets. They store data in keyβvalue pairs.
πΉ 1. What is a Dictionary?
A dictionary stores data in key:value format.
β Example:
student = { "name": "Rahul", "age": 22, "course": "Data Science" }
print(student)
Output:
{'name': 'Rahul', 'age': 22, 'course': 'Data Science'}β Uses curly brackets {}
πΉ 2. Access Dictionary Values
Use the key to access values.
student = { "name": "Rahul", "age": 22 }
print(student["name"])
Output:
RahulπΉ 3. Add New Elements
student = { "name": "Rahul", "age": 22 }
student["city"] = "Delhi"
print(student)
Output:
{'name': 'Rahul', 'age': 22, 'city': 'Delhi'}πΉ 4. Modify Values
student["age"] = 23
πΉ 5. Remove Elements
student.pop("age")
πΉ 6. Important Dictionary Methods
β
β Get Method:
print(student.get("name"))
Output:
Rahulβ Keys Method:
print(student.keys())
Output:
dict_keys(['name', 'age'])β Values Method:
print(student.values())
Output:
dict_values(['Rahul', 22])β Items Method:
print(student.items())
Output:
dict_items([('name', 'Rahul'), ('age', 22)])πΉ 7. Loop Through Dictionary
student = { "name": "Rahul", "age": 22 }
for key, value in student.items():
print(key, value)
Output:
name Rahul
age 22
π― Todayβs Goal
β Understand keyβvalue pairs
β Access dictionary values
β Add or update data
β Loop through dictionary
π Dictionaries are widely used in APIs, JSON data, and machine learning datasets.
Double Tap β₯οΈ For More
β€20π₯°1
Which symbol is used to create a dictionary in Python?
Anonymous Quiz
18%
A) []
9%
B) ()
70%
C) {}
3%
D) <>
β€2π’1
What will be the output?
student = { "name": "Rahul", "age": 22 } print(student["name"])
student = { "name": "Rahul", "age": 22 } print(student["name"])
Anonymous Quiz
82%
A) Rahul
9%
B) name
3%
C) 22
7%
D) Error
β€2
Which method returns all keys of a dictionary?
Anonymous Quiz
14%
A) values()
14%
B) items()
61%
C) keys()
11%
D) get()
β€1
What will be the output?
data = {"a":1, "b":2} data["c"] = 3 print(data)
data = {"a":1, "b":2} data["c"] = 3 print(data)
Anonymous Quiz
9%
A) {'a':1, 'b':2}
65%
B) {'a':1, 'b':2, 'c':3}
18%
C) Error
8%
D) {'c':3}
β€1π€1
Which method is used to remove an element from a dictionary?
Anonymous Quiz
44%
A) remove()
16%
B) delete()
35%
C) pop()
5%
D) clearitem()
β€8
Data Science Roadmap
β Python File Handling
ππ File handling allows Python programs to read and write data from files.
π Very important in data science because most datasets come as:
β CSV files
β Text files
β Logs
β JSON files
πΉ 1. Opening a File
Python uses the open() function.
Syntax:
Example:
π "r" β Read mode
πΉ 2. File Modes
- "r" β Read file
- "w" β Write file (overwrites existing content)
- "a" β Append file (adds to existing content)
- "r+" β Read and write
πΉ 3. Reading a File
- Read Entire File:
- Read One Line:
- Read All Lines:
πΉ 4. Writing to a File
β "w" will overwrite existing content.
πΉ 5. Append to File
β Adds content without deleting old data.
πΉ 6. Best Practice (Very Important β)
Use with statement.
β Automatically closes the file.
πΉ 7. Why File Handling is Important?
Used for:
β Reading datasets
β Saving results
β Logging machine learning models
β Data preprocessing
π― Todayβs Goal
β Understand file modes
β Read files
β Write files
β Use with open()
π File handling is used heavily when working with CSV datasets in data science.
Double Tap β₯οΈ For More
β Python File Handling
ππ File handling allows Python programs to read and write data from files.
π Very important in data science because most datasets come as:
β CSV files
β Text files
β Logs
β JSON files
πΉ 1. Opening a File
Python uses the open() function.
Syntax:
open("filename", "mode")Example:
file = open("data.txt", "r")π "r" β Read mode
πΉ 2. File Modes
- "r" β Read file
- "w" β Write file (overwrites existing content)
- "a" β Append file (adds to existing content)
- "r+" β Read and write
πΉ 3. Reading a File
- Read Entire File:
file.read()- Read One Line:
file.readline()- Read All Lines:
file.readlines()πΉ 4. Writing to a File
file = open("data.txt", "w")
file.write("Hello Data Science")
file.close()
β "w" will overwrite existing content.
πΉ 5. Append to File
file = open("data.txt", "a")
file.write("\nNew line added")
file.close()
β Adds content without deleting old data.
πΉ 6. Best Practice (Very Important β)
Use with statement.
with open("data.txt", "r") as file:
content = file.read()
print(content)
β Automatically closes the file.
πΉ 7. Why File Handling is Important?
Used for:
β Reading datasets
β Saving results
β Logging machine learning models
β Data preprocessing
π― Todayβs Goal
β Understand file modes
β Read files
β Write files
β Use with open()
π File handling is used heavily when working with CSV datasets in data science.
Double Tap β₯οΈ For More
β€12
Which function is used to open a file in Python?
Anonymous Quiz
7%
A) file()
64%
B) open()
19%
C) read()
10%
D) openfile()
β€2
β€2
What will the following code do?
file = open("data.txt", "w") file.write("Hello")
file = open("data.txt", "w") file.write("Hello")
Anonymous Quiz
4%
A) Reads file
2%
B) Deletes file
90%
C) Writes text to file
4%
D) Prints file content
β€1
Which method reads the entire file content?
Anonymous Quiz
12%
A) readline()
27%
B) readlines()
58%
C) read()
3%
D) get()
β€1
Why is the with open() statement preferred?
Anonymous Quiz
27%
A) It runs faster
55%
B) It automatically closes the file
4%
C) It deletes the file
14%
D) It prevents writing
β€2π1π₯°1
β
Python Exception Handling (tryβexcept) πβ οΈ
Exception handling helps programs handle errors gracefully instead of crashing.
π Very important in real-world applications and data processing.
πΉ 1. What is an Exception?
An exception is an error that occurs during program execution.
Example:
Output: ZeroDivisionError
This will crash the program.
πΉ 2. Using tryβexcept
We use tryβexcept to handle errors.
Syntax:
Example:
Output: Error occurred
πΉ 3. Handling Specific Exceptions
β Handles only ValueError.
πΉ 4. Using else
else runs if no error occurs.
Output: No error
πΉ 5. Using finally
finally always executes.
πΉ 6. Common Python Exceptions
β’ ZeroDivisionError: Division by zero
β’ ValueError: Invalid value
β’ TypeError: Wrong data type
β’ FileNotFoundError: File does not exist
π― Today's Goal
β Understand exceptions
β Use tryβexcept
β Handle specific errors
β Use else and finally
π Exception handling is widely used in data pipelines and production code.
Double Tap β₯οΈ For More
Exception handling helps programs handle errors gracefully instead of crashing.
π Very important in real-world applications and data processing.
πΉ 1. What is an Exception?
An exception is an error that occurs during program execution.
Example:
print(10 / 0)
Output: ZeroDivisionError
This will crash the program.
πΉ 2. Using tryβexcept
We use tryβexcept to handle errors.
Syntax:
try:
# code that may cause error
except:
# code to handle error
Example:
try:
x = 10 / 0
except:
print("Error occurred")
Output: Error occurred
πΉ 3. Handling Specific Exceptions
try:
num = int("abc")
except ValueError:
print("Invalid number")
β Handles only ValueError.
πΉ 4. Using else
else runs if no error occurs.
try:
x = 10 / 2
except:
print("Error")
else:
print("No error")
Output: No error
πΉ 5. Using finally
finally always executes.
try:
file = open("data.txt")
except:
print("File not found")
finally:
print("Execution completed")
πΉ 6. Common Python Exceptions
β’ ZeroDivisionError: Division by zero
β’ ValueError: Invalid value
β’ TypeError: Wrong data type
β’ FileNotFoundError: File does not exist
π― Today's Goal
β Understand exceptions
β Use tryβexcept
β Handle specific errors
β Use else and finally
π Exception handling is widely used in data pipelines and production code.
Double Tap β₯οΈ For More
β€10
SQL, or Structured Query Language, is a domain-specific language used to manage and manipulate relational databases. Here's a brief A-Z overview by @sqlanalyst
A - Aggregate Functions: Functions like COUNT, SUM, AVG, MIN, and MAX used to perform operations on data in a database.
B - BETWEEN: A SQL operator used to filter results within a specific range.
C - CREATE TABLE: SQL statement for creating a new table in a database.
D - DELETE: SQL statement used to delete records from a table.
E - EXISTS: SQL operator used in a subquery to test if a specified condition exists.
F - FOREIGN KEY: A field in a database table that is a primary key in another table, establishing a link between the two tables.
G - GROUP BY: SQL clause used to group rows that have the same values in specified columns.
H - HAVING: SQL clause used in combination with GROUP BY to filter the results.
I - INNER JOIN: SQL clause used to combine rows from two or more tables based on a related column between them.
J - JOIN: Combines rows from two or more tables based on a related column.
K - KEY: A field or set of fields in a database table that uniquely identifies each record.
L - LIKE: SQL operator used in a WHERE clause to search for a specified pattern in a column.
M - MODIFY: SQL command used to modify an existing database table.
N - NULL: Represents missing or undefined data in a database.
O - ORDER BY: SQL clause used to sort the result set in ascending or descending order.
P - PRIMARY KEY: A field in a table that uniquely identifies each record in that table.
Q - QUERY: A request for data from a database using SQL.
R - ROLLBACK: SQL command used to undo transactions that have not been saved to the database.
S - SELECT: SQL statement used to query the database and retrieve data.
T - TRUNCATE: SQL command used to delete all records from a table without logging individual row deletions.
U - UPDATE: SQL statement used to modify the existing records in a table.
V - VIEW: A virtual table based on the result of a SELECT query.
W - WHERE: SQL clause used to filter the results of a query based on a specified condition.
X - (E)XISTS: Used in conjunction with SELECT to test the existence of rows returned by a subquery.
Z - ZERO: Represents the absence of a value in numeric fields or the initial state of boolean fields.
A - Aggregate Functions: Functions like COUNT, SUM, AVG, MIN, and MAX used to perform operations on data in a database.
B - BETWEEN: A SQL operator used to filter results within a specific range.
C - CREATE TABLE: SQL statement for creating a new table in a database.
D - DELETE: SQL statement used to delete records from a table.
E - EXISTS: SQL operator used in a subquery to test if a specified condition exists.
F - FOREIGN KEY: A field in a database table that is a primary key in another table, establishing a link between the two tables.
G - GROUP BY: SQL clause used to group rows that have the same values in specified columns.
H - HAVING: SQL clause used in combination with GROUP BY to filter the results.
I - INNER JOIN: SQL clause used to combine rows from two or more tables based on a related column between them.
J - JOIN: Combines rows from two or more tables based on a related column.
K - KEY: A field or set of fields in a database table that uniquely identifies each record.
L - LIKE: SQL operator used in a WHERE clause to search for a specified pattern in a column.
M - MODIFY: SQL command used to modify an existing database table.
N - NULL: Represents missing or undefined data in a database.
O - ORDER BY: SQL clause used to sort the result set in ascending or descending order.
P - PRIMARY KEY: A field in a table that uniquely identifies each record in that table.
Q - QUERY: A request for data from a database using SQL.
R - ROLLBACK: SQL command used to undo transactions that have not been saved to the database.
S - SELECT: SQL statement used to query the database and retrieve data.
T - TRUNCATE: SQL command used to delete all records from a table without logging individual row deletions.
U - UPDATE: SQL statement used to modify the existing records in a table.
V - VIEW: A virtual table based on the result of a SELECT query.
W - WHERE: SQL clause used to filter the results of a query based on a specified condition.
X - (E)XISTS: Used in conjunction with SELECT to test the existence of rows returned by a subquery.
Z - ZERO: Represents the absence of a value in numeric fields or the initial state of boolean fields.
β€13π1
β
NumPy Basics ππ
NumPy (Numerical Python) is the most important library for numerical computing in Python.
It is widely used in:
β Data Science
β Machine Learning
β AI
β Scientific computing
πΉ 1. What is NumPy?
NumPy provides a powerful data structure called NumPy Array. It is faster and more efficient than Python lists for mathematical operations.
Example:
πΉ 2. Creating a NumPy Array
From a List
Output:
πΉ 3. Check Array Type
Output:
πΉ 4. NumPy Array Operations
Addition:
Output:
Multiplication:
Output:
πΉ 5. NumPy Built-in Functions
Output:
πΉ 6. NumPy Array Shape
Output:
Meaning: 2 rows and 3 columns.
πΉ 7. Why NumPy is Important?
NumPy is the foundation of data science libraries:
β Pandas
β Scikit-Learn
β TensorFlow
β PyTorch
All these libraries use NumPy internally.
π― Today's Goal
β Install NumPy
β Create arrays
β Perform math operations
β Understand array shape
Double Tap β₯οΈ For More
NumPy (Numerical Python) is the most important library for numerical computing in Python.
It is widely used in:
β Data Science
β Machine Learning
β AI
β Scientific computing
πΉ 1. What is NumPy?
NumPy provides a powerful data structure called NumPy Array. It is faster and more efficient than Python lists for mathematical operations.
Example:
import numpy as np
πΉ 2. Creating a NumPy Array
From a List
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr)
Output:
[1 2 3 4]
πΉ 3. Check Array Type
print(type(arr))
Output:
<class 'numpy.ndarray'>
πΉ 4. NumPy Array Operations
Addition:
import numpy as np
arr = np.array([1, 2, 3])
print(arr + 2)
Output:
[3 4 5]
Multiplication:
print(arr * 2)
Output:
[2 4 6]
πΉ 5. NumPy Built-in Functions
arr = np.array([10, 20, 30, 40])
print(arr.sum())
print(arr.mean())
print(arr.max())
print(arr.min())
Output:
100
25.0
40
10
πΉ 6. NumPy Array Shape
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.shape)
Output:
(2, 3)
Meaning: 2 rows and 3 columns.
πΉ 7. Why NumPy is Important?
NumPy is the foundation of data science libraries:
β Pandas
β Scikit-Learn
β TensorFlow
β PyTorch
All these libraries use NumPy internally.
π― Today's Goal
β Install NumPy
β Create arrays
β Perform math operations
β Understand array shape
Double Tap β₯οΈ For More
β€16π2
What does NumPy stand for?
Anonymous Quiz
83%
A) Numerical Python
6%
B) Number Python
9%
C) Numeric Program
1%
D) None
β€4
Which function is used to create a NumPy array?
Anonymous Quiz
5%
A) np.list()
89%
B) np.array()
6%
C) np.create()
0%
D) np.make()
β€6
What will be the output?
import numpy as np arr = np.array([1, 2, 3]) print(arr + 1)
import numpy as np arr = np.array([1, 2, 3]) print(arr + 1)
Anonymous Quiz
7%
A) [1 2 3]
70%
B) [2 3 4]
5%
C) [1 3 4]
17%
D) Error
β€5
What will be the output?
arr = np.array([10, 20, 30]) print(arr.mean())
arr = np.array([10, 20, 30]) print(arr.mean())
Anonymous Quiz
64%
A) 20
25%
B) 30
6%
C) 10
5%
D) Error
β€4