๐ฐ 3 years of experience. Still waiting for a salary jump?
Experience alone doesn't guarantee growth.
Learning in-demand skills can help you stay competitive in today's job market.
That's why people are joining E&ICT Academy IIT Roorkee's AI & ML Program.
โ 6 Months | Online | Open for all backgrounds
โ Learn from IIT professors & industry mentors
โ Flipkart & Mamaearth projects
โ Placement support through Masai's network of 5000+ companies
๐ Entrance Test: 26th July
๐ https://tinyurl.com/DS-26Jul-006
Experience alone doesn't guarantee growth.
Learning in-demand skills can help you stay competitive in today's job market.
That's why people are joining E&ICT Academy IIT Roorkee's AI & ML Program.
โ 6 Months | Online | Open for all backgrounds
โ Learn from IIT professors & industry mentors
โ Flipkart & Mamaearth projects
โ Placement support through Masai's network of 5000+ companies
๐ Entrance Test: 26th July
๐ https://tinyurl.com/DS-26Jul-006
โค5
๐ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ฆ๐ค๐ ๐๐ผ๐ฟ ๐๐ฅ๐๐! ๐๏ธ๐ป
Start learning SQL with these 100% FREE resources and build one of the most in-demand skills in tech!
โ Beginner-Friendly SQL Tutorials
โ FREE Online SQL Courses
โ Interactive SQL Practice Platforms
โ Real-World Database Projects
โ Interview Preparation Resources
โ Hands-on Exercises & Challenges
๐๐ป๐ฟ๐ผ๐น๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐๐:-
https://pdlink.in/4yLrNci
๐ Start your SQL journey today and unlock exciting career opportunities!
Start learning SQL with these 100% FREE resources and build one of the most in-demand skills in tech!
โ Beginner-Friendly SQL Tutorials
โ FREE Online SQL Courses
โ Interactive SQL Practice Platforms
โ Real-World Database Projects
โ Interview Preparation Resources
โ Hands-on Exercises & Challenges
๐๐ป๐ฟ๐ผ๐น๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐๐:-
https://pdlink.in/4yLrNci
๐ Start your SQL journey today and unlock exciting career opportunities!
โค4
Data Science & Machine Learning
๐ฐ 3 years of experience. Still waiting for a salary jump? Experience alone doesn't guarantee growth. Learning in-demand skills can help you stay competitive in today's job market. That's why people are joining E&ICT Academy IIT Roorkee's AI & ML Program.โฆ
Last 6 Hours Remaining!
Before the application closes for E&ICT IIT Roorkee AI & ML Program.
Don't miss out on the chance to:
โข Learn live from IIT professors & industry experts
โข Build real AI projects
โข Get Placement Support from Masai.
Register NOW
Before the application closes for E&ICT IIT Roorkee AI & ML Program.
Don't miss out on the chance to:
โข Learn live from IIT professors & industry experts
โข Build real AI projects
โข Get Placement Support from Masai.
Register NOW
โค2๐1
๐ ๐๐๐ฏ๐ฒ๐ฟ๐๐ฒ๐ฐ๐๐ฟ๐ถ๐๐ & ๐๐น๐ผ๐๐ฑ ๐๐ผ๐บ๐ฝ๐๐๐ถ๐ป๐ด ๐๐ฅ๐๐ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป ๐๐ผ๐๐ฟ๐๐ฒ๐
Build job-ready skills in two of the most in-demand technology fields and strengthen your rรฉsumรฉ with valuable certifications! ๐
๐ Cyber Security :- https://pdlink.in/4bHIF9K
โ
โ๏ธ Cloud Computing :- https://pdlink.in/4yXs8bU
โ
Perfect for Students, Freshers & Working Professionals looking to launch or upgrade their tech careers. ๐ผ
๐ Enroll for FREE & Get Certified
Build job-ready skills in two of the most in-demand technology fields and strengthen your rรฉsumรฉ with valuable certifications! ๐
๐ Cyber Security :- https://pdlink.in/4bHIF9K
โ
โ๏ธ Cloud Computing :- https://pdlink.in/4yXs8bU
โ
Perfect for Students, Freshers & Working Professionals looking to launch or upgrade their tech careers. ๐ผ
๐ Enroll for FREE & Get Certified
โค1
๐ Data Science Roadmap 2026
๐ Phase 1: Programming Fundamentals
๐ Topic 8: Python List Comprehensions
Welcome back! ๐
In the previous lesson, you learned about Python's built-in data structuresโLists, Tuples, Sets, and Dictionaries.
Now it's time to learn one of Python's most elegant and frequently used features: List Comprehensions.
List comprehensions provide a concise and readable way to create, filter, and transform lists. They are widely used in Data Science, Machine Learning, data preprocessing, and coding interviews.
๐น 1. What is a List Comprehension?
A list comprehension is a compact way to create a new list by applying an expression to each item in an iterable (such as a list, tuple, or range).
Instead of writing multiple lines with a loop, you can accomplish the same task in a single line.
General Syntax
๐น 2. Creating a List Using a Loop
Output
๐น 3. Creating the Same List Using List Comprehension
Output
Notice how the code is shorter and easier to read.
๐น 4. Performing Calculations
Create a list of squares.
Output
๐น 5. Using Conditions
You can filter elements while creating a list.
Example: Even Numbers
Output
๐น 6. Converting Strings
Convert all names to uppercase.
Output
๐น 7. Using Conditional Expressions
Replace negative numbers with zero.
Output
๐น 8. Nested List Comprehension
Create a multiplication table.
Output
๐น 9. Real-World Data Science Example
Suppose you have a list of sales amounts.
๐ Phase 1: Programming Fundamentals
๐ Topic 8: Python List Comprehensions
Welcome back! ๐
In the previous lesson, you learned about Python's built-in data structuresโLists, Tuples, Sets, and Dictionaries.
Now it's time to learn one of Python's most elegant and frequently used features: List Comprehensions.
List comprehensions provide a concise and readable way to create, filter, and transform lists. They are widely used in Data Science, Machine Learning, data preprocessing, and coding interviews.
๐น 1. What is a List Comprehension?
A list comprehension is a compact way to create a new list by applying an expression to each item in an iterable (such as a list, tuple, or range).
Instead of writing multiple lines with a loop, you can accomplish the same task in a single line.
General Syntax
new_list = [expression for item in iterable]๐น 2. Creating a List Using a Loop
numbers = []
for i in range(5):
numbers.append(i)
print(numbers)
Output
[0, 1, 2, 3, 4]๐น 3. Creating the Same List Using List Comprehension
numbers = [i for i in range(5)]
print(numbers)
Output
[0, 1, 2, 3, 4] Notice how the code is shorter and easier to read.
๐น 4. Performing Calculations
Create a list of squares.
squares = [x ** 2 for x in range(1, 6)]
print(squares)
Output
[1, 4, 9, 16, 25]๐น 5. Using Conditions
You can filter elements while creating a list.
Example: Even Numbers
even_numbers = [x for x in range(1, 11) if x % 2 == 0]
print(even_numbers)
Output
[2, 4, 6, 8, 10]๐น 6. Converting Strings
Convert all names to uppercase.
names = ["rahul", "deepak", "anita"]
upper_names = [name.upper() for name in names]
print(upper_names)
Output
['RAHUL', 'DEEPAK', 'ANITA']๐น 7. Using Conditional Expressions
Replace negative numbers with zero.
numbers = [5, -2, 8, -1, 3]
updated = [0 if x < 0 else x for x in numbers]
print(updated)
Output
[5, 0, 8, 0, 3]๐น 8. Nested List Comprehension
Create a multiplication table.
table = [[i * j for j in range(1, 6)] for i in range(1, 4)]
print(table)
Output
[[1, 2, 3, 4, 5],
[2, 4, 6, 8, 10],
[3, 6, 9, 12, 15]]
๐น 9. Real-World Data Science Example
Suppose you have a list of sales amounts.
sales = [1200, 850, 1500, 600, 2000]
high_sales = [sale for sale in sales if sale > 1000]
print(high_sales)
โค3
Output
This technique is commonly used while cleaning and filtering datasets before analysis.
๐น 10. Benefits of List Comprehensions
โ Shorter code
โ Easier to read
โ Faster than traditional loops in many cases
โ Widely used in Data Science and Machine Learning
๐น 11. Common Mistakes
โ Forgetting the Expression
Correct:
โ Incorrect Order of "if"
Correct:
๐ฏ Practice Questions
1. Create a list of numbers from 1 to 20.
2. Create a list containing the squares of numbers from 1 to 10.
3. Create a list containing only odd numbers from 1 to 20.
4. Convert a list of names to lowercase.
5. Replace all negative values in a list with zero using a list comprehension.
๐ฏ Key Takeaways
โ List comprehensions provide a concise way to create lists.
โ They combine loops and expressions into a single line.
โ You can filter data using "if" conditions.
โ Conditional expressions allow values to be modified during list creation.
โ List comprehensions are widely used in data cleaning, feature engineering, and machine learning workflows.
Mastering list comprehensions will help you write cleaner, more Pythonic code and prepare you for technical interviews and real-world Data Science projects.
Double Tap โค๏ธ For Part-9
[1200, 1500, 2000] This technique is commonly used while cleaning and filtering datasets before analysis.
๐น 10. Benefits of List Comprehensions
โ Shorter code
โ Easier to read
โ Faster than traditional loops in many cases
โ Widely used in Data Science and Machine Learning
๐น 11. Common Mistakes
โ Forgetting the Expression
numbers = [for i in range(5)] # SyntaxErrorCorrect:
numbers = [i for i in range(5)]โ Incorrect Order of "if"
numbers = [if x % 2 == 0 x for x in range(10)]Correct:
numbers = [x for x in range(10) if x % 2 == 0]๐ฏ Practice Questions
1. Create a list of numbers from 1 to 20.
2. Create a list containing the squares of numbers from 1 to 10.
3. Create a list containing only odd numbers from 1 to 20.
4. Convert a list of names to lowercase.
5. Replace all negative values in a list with zero using a list comprehension.
๐ฏ Key Takeaways
โ List comprehensions provide a concise way to create lists.
โ They combine loops and expressions into a single line.
โ You can filter data using "if" conditions.
โ Conditional expressions allow values to be modified during list creation.
โ List comprehensions are widely used in data cleaning, feature engineering, and machine learning workflows.
Mastering list comprehensions will help you write cleaner, more Pythonic code and prepare you for technical interviews and real-world Data Science projects.
Double Tap โค๏ธ For Part-9
โค10
๐ฐ India needs 10 lakh+ AI/ML professionals by end of 2026.
Half those roles canโt find qualified candidates.
Thatโs not a job market. Thatโs an open goal.
Certification in AI & ML - Vishlesan i-Hub, IIT Patna
โ Scikit-learn โ PyTorch โ Transformers โ RAG & Agents
โ Deploy models with FastAPI, Docker & MLOps
โ Live learning from IIT faculty & industry mentors
โ Placement support through Masai's network of 5000+ companies
The qualifier is this Sunday. One attempt.
๐ โน99 Test - 2nd August
๐ https://tinyurl.com/DS-29JUL-006
Half those roles canโt find qualified candidates.
Thatโs not a job market. Thatโs an open goal.
Certification in AI & ML - Vishlesan i-Hub, IIT Patna
โ Scikit-learn โ PyTorch โ Transformers โ RAG & Agents
โ Deploy models with FastAPI, Docker & MLOps
โ Live learning from IIT faculty & industry mentors
โ Placement support through Masai's network of 5000+ companies
The qualifier is this Sunday. One attempt.
๐ โน99 Test - 2nd August
๐ https://tinyurl.com/DS-29JUL-006
โค4
๐ Data Science Roadmap 2026
๐ Phase 1: Programming Fundamentals
๐ Topic 9: Python Lambda Functions, map(), filter(), and reduce()
Welcome back! ๐
So far, you've learned Python basics, loops, functions, data structures, and list comprehensions. In this lesson, you'll learn functional programming concepts in Python using Lambda Functions, map(), filter(), and reduce().
These are widely used in Data Science for transforming, filtering, and processing large datasets efficiently.
๐น 1. What is a Lambda Function?
A Lambda Function is a small anonymous function that can have any number of arguments but only one expression.
Unlike normal functions, lambda functions don't require a name.
Syntax
Example
Output:
This is equivalent to:
๐น 2. Why Use Lambda Functions?
Lambda functions are useful when:
โ You need a simple function only once.
โ You want shorter, cleaner code.
โ You're using functions like map(), filter(), or sorted().
๐น 3. Lambda with Multiple Arguments
Output:
๐น 4. The map() Function
The map() function applies a function to every item in an iterable.
Syntax:
Example
Output:
๐น 5. Using map() with a Normal Function
Output:
๐น 6. The filter() Function
The filter() function selects only those elements that satisfy a condition.
Syntax:
Example
Output:
๐น 7. The reduce() Function
The reduce() function applies a function repeatedly to reduce an iterable to a single value.
It is available in the
Output:
๐น 8. Difference Between map(), filter(), and reduce()
map(): Transforms every element in an iterable and returns a new iterable.
filter(): Keeps only elements that match a condition and returns a filtered iterable.
reduce(): Combines all elements into a single value.
๐น 9. Real-World Data Science Example
Suppose you have customer purchase amounts.
Output:
Now calculate the total revenue.
Output:
๐น 10. Combining map() and filter()
๐ Phase 1: Programming Fundamentals
๐ Topic 9: Python Lambda Functions, map(), filter(), and reduce()
Welcome back! ๐
So far, you've learned Python basics, loops, functions, data structures, and list comprehensions. In this lesson, you'll learn functional programming concepts in Python using Lambda Functions, map(), filter(), and reduce().
These are widely used in Data Science for transforming, filtering, and processing large datasets efficiently.
๐น 1. What is a Lambda Function?
A Lambda Function is a small anonymous function that can have any number of arguments but only one expression.
Unlike normal functions, lambda functions don't require a name.
Syntax
lambda arguments: expressionExample
square = lambda x: x * x
print(square(5))
Output:
25This is equivalent to:
def square(x):
return x * x
๐น 2. Why Use Lambda Functions?
Lambda functions are useful when:
โ You need a simple function only once.
โ You want shorter, cleaner code.
โ You're using functions like map(), filter(), or sorted().
๐น 3. Lambda with Multiple Arguments
add = lambda a, b: a + b
print(add(10, 20))
Output:
30๐น 4. The map() Function
The map() function applies a function to every item in an iterable.
Syntax:
map(function, iterable)Example
numbers = [1, 2, 3, 4, 5]
squares = list(map(lambda x: x ** 2, numbers))
print(squares)
Output:
[1, 4, 9, 16, 25]๐น 5. Using map() with a Normal Function
def double(x):
return x * 2
numbers = [1, 2, 3, 4]
result = list(map(double, numbers))
print(result)
Output:
[2, 4, 6, 8]๐น 6. The filter() Function
The filter() function selects only those elements that satisfy a condition.
Syntax:
filter(function, iterable)Example
numbers = [1, 2, 3, 4, 5, 6]
even = list(filter(lambda x: x % 2 == 0, numbers))
print(even)
Output:
[2, 4, 6]๐น 7. The reduce() Function
The reduce() function applies a function repeatedly to reduce an iterable to a single value.
It is available in the
functools module.from functools import reduce
numbers = [1, 2, 3, 4]
result = reduce(lambda a, b: a + b, numbers)
print(result)
Output:
10๐น 8. Difference Between map(), filter(), and reduce()
map(): Transforms every element in an iterable and returns a new iterable.
filter(): Keeps only elements that match a condition and returns a filtered iterable.
reduce(): Combines all elements into a single value.
๐น 9. Real-World Data Science Example
Suppose you have customer purchase amounts.
purchases = [1200, 450, 1800, 900, 2500]
high_value = list(filter(lambda x: x > 1000, purchases))
print(high_value)
Output:
[1200, 1800, 2500]Now calculate the total revenue.
from functools import reduce
total = reduce(lambda a, b: a + b, purchases)
print(total)
Output:
6850๐น 10. Combining map() and filter()
numbers = [1, 2, 3, 4, 5, 6]
result = list(
map(
lambda x: x * 10,
filter(lambda x: x % 2 == 0, numbers)
)
)
print(result)
โค5
Output:
First, filter() keeps only even numbers.
Then, map() multiplies each by 10.
๐น 11. Common Mistakes
โ Forgetting to Convert map() to a List
โ
Correct:
โ Forgetting to Import reduce()
โ
Correct:
๐ฏ Practice Questions
1. Create a lambda function that returns the cube of a number.
2. Use map() to convert a list of temperatures from Celsius to Fahrenheit.
3. Use filter() to find numbers greater than 50.
4. Use reduce() to calculate the product of a list of numbers.
5. Combine filter() and map() to square only the odd numbers in a list.
๐ฏ Key Takeaways
โ Lambda functions are short, anonymous functions.
โ map() transforms every element in an iterable.
โ filter() selects elements based on a condition.
โ reduce() combines all elements into a single value.
โ These functions are widely used for data transformation, preprocessing, and feature engineering in Data Science.
Double Tap โค๏ธ For More
[20, 40, 60]
First, filter() keeps only even numbers.
Then, map() multiplies each by 10.
๐น 11. Common Mistakes
โ Forgetting to Convert map() to a List
result = map(lambda x: x * 2, numbers)
โ
<map object at ...>
Correct:
print(list(result))
โ Forgetting to Import reduce()
result = reduce(lambda a, b: a + b, [1, 2, 3])
โ
NameError
Correct:
from functools import reduce
๐ฏ Practice Questions
1. Create a lambda function that returns the cube of a number.
2. Use map() to convert a list of temperatures from Celsius to Fahrenheit.
3. Use filter() to find numbers greater than 50.
4. Use reduce() to calculate the product of a list of numbers.
5. Combine filter() and map() to square only the odd numbers in a list.
๐ฏ Key Takeaways
โ Lambda functions are short, anonymous functions.
โ map() transforms every element in an iterable.
โ filter() selects elements based on a condition.
โ reduce() combines all elements into a single value.
โ These functions are widely used for data transformation, preprocessing, and feature engineering in Data Science.
Double Tap โค๏ธ For More
โค7
Last 25 seats | Batch closing this week!
โ
โ๐๐ & ๐๐ฎ๐๐ฎ ๐ฆ๐ฐ๐ถ๐ฒ๐ป๐ฐ๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ (๐ก๐ผ ๐๐ผ๐ฑ๐ถ๐ป๐ด ๐ก๐ฒ๐ฒ๐ฑ๐ฒ๐ฑ)
E&ICT Academy, IIT Roorkee is closing admissions for their Data Science & AI Certification on 2nd August 2026.
โ No coding background needed
โ IIT faculty-led program
โ Certificate from E&ICT IIT Roorkee
๐๐ฝ๐ฝ๐น๐ ๐ฏ๐ฒ๐ณ๐ผ๐ฟ๐ฒ ๐๐ฒ๐ฎ๐๐ ๐ณ๐ถ๐น๐น ๐๐ฝ:-
https://pdlink.in/4aYWald
๐ซDeadline: 2nd August 2026
โ
โ๐๐ & ๐๐ฎ๐๐ฎ ๐ฆ๐ฐ๐ถ๐ฒ๐ป๐ฐ๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ (๐ก๐ผ ๐๐ผ๐ฑ๐ถ๐ป๐ด ๐ก๐ฒ๐ฒ๐ฑ๐ฒ๐ฑ)
E&ICT Academy, IIT Roorkee is closing admissions for their Data Science & AI Certification on 2nd August 2026.
โ No coding background needed
โ IIT faculty-led program
โ Certificate from E&ICT IIT Roorkee
๐๐ฝ๐ฝ๐น๐ ๐ฏ๐ฒ๐ณ๐ผ๐ฟ๐ฒ ๐๐ฒ๐ฎ๐๐ ๐ณ๐ถ๐น๐น ๐๐ฝ:-
https://pdlink.in/4aYWald
๐ซDeadline: 2nd August 2026
โค5๐1
๐ Data Science Roadmap 2026
๐ Phase 1: Programming Fundamentals
๐ Topic 10: Python Modules, Packages & File Handling
Welcome back! ๐
So far, you've learned Python fundamentals, functions, data structures, list comprehensions, and functional programming. In this lesson, you'll learn how to organize your code into modules and packages and how to read from and write to files.
These skills are essential for every Data Scientist because real-world projects involve working with multiple Python files, libraries, and datasets stored in files.
๐น 1. What is a Module?
A module is a Python file (".py") that contains functions, variables, or classes that can be reused in other Python programs.
Instead of writing the same code repeatedly, you can create a module once and import it wherever needed.
Example:
Suppose you have a file named
Now use it in another file:
Output:
๐น 2. Importing Modules
Python provides different ways to import modules.
Import the Entire Module
Output:
Import Specific Functions
Output:
Import with an Alias
Aliases make long module names easier to use.
Output:
๐น 3. Common Built-in Modules
Some commonly used Python modules are:
โข "math" โ Mathematical operations
โข "random" โ Generate random numbers
โข "datetime" โ Work with dates and times
โข "os" โ Interact with the operating system
โข "sys" โ Access system-specific information
โข "statistics" โ Perform statistical calculations
Example:
This generates a random integer between 1 and 10.
๐น 4. What is a Package?
A package is a collection of related modules organized into folders.
Example:
Packages help organize large Python projects into manageable sections.
๐น 5. File Handling
Most Data Science projects involve reading data from files such as:
โข CSV files
โข Text files
โข Excel files
โข JSON files
Python provides built-in functions for file handling.
๐น 6. Opening a File
Syntax:
Common modes:
Mode | Description
"r" | Read
"w" | Write (overwrites existing content)
"a" | Append
"x" | Create a new file
"rb" | Read binary files
"wb" | Write binary files
๐น 7. Reading a File
Suppose
Python code:
Output:
๐น 8. Writing to a File
This replaces the previous contents of the file.
๐น 9. Appending to a File
๐ Phase 1: Programming Fundamentals
๐ Topic 10: Python Modules, Packages & File Handling
Welcome back! ๐
So far, you've learned Python fundamentals, functions, data structures, list comprehensions, and functional programming. In this lesson, you'll learn how to organize your code into modules and packages and how to read from and write to files.
These skills are essential for every Data Scientist because real-world projects involve working with multiple Python files, libraries, and datasets stored in files.
๐น 1. What is a Module?
A module is a Python file (".py") that contains functions, variables, or classes that can be reused in other Python programs.
Instead of writing the same code repeatedly, you can create a module once and import it wherever needed.
Example:
Suppose you have a file named
calculator.pydef add(a, b):
return a + b
def subtract(a, b):
return a - b
Now use it in another file:
import calculator
print(calculator.add(10, 5))
Output:
15๐น 2. Importing Modules
Python provides different ways to import modules.
Import the Entire Module
import math
print(math.sqrt(25))
Output:
5.0Import Specific Functions
from math import sqrt
print(sqrt(49))
Output:
7.0Import with an Alias
Aliases make long module names easier to use.
import math as m
print(m.pi)
Output:
3.141592653589793๐น 3. Common Built-in Modules
Some commonly used Python modules are:
โข "math" โ Mathematical operations
โข "random" โ Generate random numbers
โข "datetime" โ Work with dates and times
โข "os" โ Interact with the operating system
โข "sys" โ Access system-specific information
โข "statistics" โ Perform statistical calculations
Example:
import random
print(random.randint(1, 10))
This generates a random integer between 1 and 10.
๐น 4. What is a Package?
A package is a collection of related modules organized into folders.
Example:
project/
โ
โโโ main.py
โโโ utilities/
โ โโโ init.py
โ โโโ calculator.py
โ โโโ helper.py
Packages help organize large Python projects into manageable sections.
๐น 5. File Handling
Most Data Science projects involve reading data from files such as:
โข CSV files
โข Text files
โข Excel files
โข JSON files
Python provides built-in functions for file handling.
๐น 6. Opening a File
Syntax:
open(file_name, mode)Common modes:
Mode | Description
"r" | Read
"w" | Write (overwrites existing content)
"a" | Append
"x" | Create a new file
"rb" | Read binary files
"wb" | Write binary files
๐น 7. Reading a File
Suppose
sample.txt contains:Welcome to Python
Learning File Handling
Python code:
file = open("sample.txt", "r")
print(file.read())
file.close()Output:
Welcome to Python
Learning File Handling
๐น 8. Writing to a File
file = open("sample.txt", "w")
file.write("Hello Data Science!")
file.close()This replaces the previous contents of the file.
๐น 9. Appending to a File
file = open("sample.txt", "a")
file.write("\nPython is awesome!")
file.close()โค1
This adds new content without removing existing data.
๐น 10. Using the "with" Statement โญ
The recommended way to work with files is by using the "with" statement.
It automatically closes the file after use.
You don't need to call
manually.
๐น 11. Reading a File Line by Line
This is useful for processing large files efficiently.
๐น 12. Real-World Data Science Example
Suppose you have a text file containing sales data:
Python code:
Output:
In real-world projects, similar logic is used to process datasets before loading them into Pandas.
๐น 13. Common Mistakes
โ Forgetting to Close the File
Always use:
โ Opening a Non-Existent File
If the file doesn't exist, Python raises a
.
Always verify that the file exists or handle exceptions appropriately.
๐ฏ Practice Questions
1. Create your own Python module with two functions and import it into another file.
2. Import the "math" module and calculate the square root of 144.
3. Create a text file and write five lines into it.
4. Read a text file line by line using the "with" statement.
5. Read a file containing numbers and calculate their average.
๐ฏ Key Takeaways
โ A module is a reusable Python file containing code.
โ A package is a collection of related modules.
โ Use "import" to access modules and their functions.
โ Use "open()" to read and write files.
โ Prefer the "with" statement because it automatically closes files.
โ File handling is a fundamental skill for reading datasets, logs, configuration files, and other real-world data sources.
Mastering modules, packages, and file handling will prepare you for working with Python libraries like Pandas, NumPy, and Scikit-learn, where data is frequently loaded from external files.
Double Tap โค๏ธ For More
๐น 10. Using the "with" Statement โญ
The recommended way to work with files is by using the "with" statement.
It automatically closes the file after use.
with open("sample.txt", "r") as file:
print(file.read())You don't need to call
close()
manually.
๐น 11. Reading a File Line by Line
with open("sample.txt", "r") as file:
for line in file:
print(line.strip())This is useful for processing large files efficiently.
๐น 12. Real-World Data Science Example
Suppose you have a text file containing sales data:
100
250
175
300
Python code:
total = 0
with open("sales.txt", "r") as file:
for line in file:
total += int(line)
print(total)
Output:
825
In real-world projects, similar logic is used to process datasets before loading them into Pandas.
๐น 13. Common Mistakes
โ Forgetting to Close the File
file = open("sample.txt", "r")
print(file.read())Always use:
with open("sample.txt", "r") as file:
print(file.read())โ Opening a Non-Existent File
open("data.txt", "r")If the file doesn't exist, Python raises a
FileNotFoundError
.
Always verify that the file exists or handle exceptions appropriately.
๐ฏ Practice Questions
1. Create your own Python module with two functions and import it into another file.
2. Import the "math" module and calculate the square root of 144.
3. Create a text file and write five lines into it.
4. Read a text file line by line using the "with" statement.
5. Read a file containing numbers and calculate their average.
๐ฏ Key Takeaways
โ A module is a reusable Python file containing code.
โ A package is a collection of related modules.
โ Use "import" to access modules and their functions.
โ Use "open()" to read and write files.
โ Prefer the "with" statement because it automatically closes files.
โ File handling is a fundamental skill for reading datasets, logs, configuration files, and other real-world data sources.
Mastering modules, packages, and file handling will prepare you for working with Python libraries like Pandas, NumPy, and Scikit-learn, where data is frequently loaded from external files.
Double Tap โค๏ธ For More
โค8๐1
๐๐๐ฒ ๐๐๐ญ๐๐ซ ๐๐ฅ๐๐๐๐ฆ๐๐ง๐ญ - ๐๐๐ญ ๐๐ฅ๐๐๐๐ ๐๐ง ๐๐จ๐ฉ ๐๐๐'๐ฌ ๐
Learn Coding From Scratch - Lectures Taught By IIT Alumni
๐ซUpskill on the most in-demand skills in the market
๐๐ถ๐ด๐ต๐น๐ถ๐ด๐ต๐๐:-
๐ผ Avg. Package: โน7.2 LPA | Highest: โน41 LPA
๐ Trusted by 7500+ Students
๐ค 500+ Hiring Partners
Eligibility: BTech / BCA / BSc / MCA / MSc
๐๐๐ ๐ข๐ฌ๐ญ๐๐ซ ๐๐จ๐ฐ ๐:-
https://pdlink.in/42WOE5H
Hurry! Limited seats are available.๐โโ๏ธ
Learn Coding From Scratch - Lectures Taught By IIT Alumni
๐ซUpskill on the most in-demand skills in the market
๐๐ถ๐ด๐ต๐น๐ถ๐ด๐ต๐๐:-
๐ผ Avg. Package: โน7.2 LPA | Highest: โน41 LPA
๐ Trusted by 7500+ Students
๐ค 500+ Hiring Partners
Eligibility: BTech / BCA / BSc / MCA / MSc
๐๐๐ ๐ข๐ฌ๐ญ๐๐ซ ๐๐จ๐ฐ ๐:-
https://pdlink.in/42WOE5H
Hurry! Limited seats are available.๐โโ๏ธ
What is the difference between "w" mode and "a" mode when opening a file?
Anonymous Quiz
4%
A) Both work exactly the same way.
93%
B) "w" overwrites the file, while "a" adds new content to the end of the file.
1%
C) "w" is used only for binary files.
2%
D) "a" can only read files.
What will happen if you try to open a file in read mode ("r") that does not exist?
Anonymous Quiz
23%
A) A new file is created automatically.
8%
B) The program ignores the error.
62%
C) Python raises a FileNotFoundError.
8%
D) The file opens as empty.
โค2
Which file mode is used to append data to an existing file without deleting its contents?
Anonymous Quiz
9%
A) "r"
13%
B) "w"
68%
C) "a"
9%
D) "x"
What is a Python module?
Anonymous Quiz
19%
A) A collection of databases
76%
B) A Python file (.py) containing reusable code
2%
C) A folder containing images
3%
D) A Python keyword
๐ ๐๐ฎ๐๐ฎ ๐๐ป๐ฎ๐น๐๐๐ถ๐ฐ๐ ๐๐ป๐๐ฒ๐ฟ๐ป๐๐ต๐ถ๐ฝ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ ๐
Company Name :- Collegedunia
โ Role: Data Analyst Intern
๐ Location: Gurugram, Haryana
๐ข Work Mode: On-site
๐ฉโ๐ป Experience: Freshers / Students
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐ ๐:
https://pdlink.in/3RNPbF7
โณ Apply Before the link expires!
Company Name :- Collegedunia
โ Role: Data Analyst Intern
๐ Location: Gurugram, Haryana
๐ข Work Mode: On-site
๐ฉโ๐ป Experience: Freshers / Students
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐ ๐:
https://pdlink.in/3RNPbF7
โณ Apply Before the link expires!
โค2๐ฅ1
Data Science & Machine Learning
๐ฐ India needs 10 lakh+ AI/ML professionals by end of 2026. Half those roles canโt find qualified candidates. Thatโs not a job market. Thatโs an open goal. Certification in AI & ML - Vishlesan i-Hub, IIT Patna โ
Scikit-learn โ PyTorch โ Transformersโฆ
โณ 10 lakh AI roles. One test. Tomorrow.
Scikit-learn โ PyTorch โ Transformers โ RAG & Agents. The 9-month roadmap starts with a 60-min aptitude test.
Vishlesan i-Hub, IIT Patna โน99 ยท Sunday, 2nd Aug ยท one attempt
๐ https://tinyurl.com/DS-29JUL-006
Scikit-learn โ PyTorch โ Transformers โ RAG & Agents. The 9-month roadmap starts with a 60-min aptitude test.
Vishlesan i-Hub, IIT Patna โน99 ยท Sunday, 2nd Aug ยท one attempt
๐ https://tinyurl.com/DS-29JUL-006
โค2๐คฉ1
๐ Data Science Roadmap 2026
๐ Phase 2: Mathematics for Data Science
๐ Topic 1: Basic Mathematics (Arithmetic, Fractions, Exponents & Logarithms)
Now it's time to build the mathematical foundation behind Machine Learning and Artificial Intelligence.
๐น 1. Why Mathematics is Important in Data Science?
Mathematics helps Data Scientists:
โ Understand Machine Learning algorithms
โ Analyze data correctly
โ Optimize models
โ Measure performance
Without mathematics, it becomes difficult to understand how models learn from data.
๐น 2. Arithmetic Operations
Arithmetic is the foundation of all mathematical calculations.
The five basic operations are:
Addition: Symbol +
Example: 10 + 5 = 15
Subtraction: Symbol -
Example: 10 - 5 = 5
Multiplication: Symbol ร
Example: 10 ร 5 = 50
Division: Symbol รท
Example: 10 รท 5 = 2
Modulus: Symbol %
Example: 10 % 3 = 1
๐น 3. Order of Operations (BODMAS / PEMDAS)
When an expression contains multiple operations, follow this order:
1. Brackets ( )
2. Orders (Powers/Roots)
3. Division
4. Multiplication
5. Addition
6. Subtraction
Example: 5 + 2 ร 3
First perform multiplication: 2 ร 3 = 6
Then addition: 5 + 6 = 11
๐น 4. Fractions
A fraction represents a part of a whole.
Example: 3/4
Here: Numerator = 3, Denominator = 4
Converting Fractions to Decimals
Example: 3 รท 4 = 0.75
Converting Decimals to Percentages
Multiply by 100.
Example: 0.75 ร 100 = 75%
๐น 5. Percentages
Percentage means "per hundred."
Formula: Percentage = (Part / Total) ร 100
Example: A student scored 90 out of 120. (90 / 120) ร 100 = 75%
Percentages are widely used in: Accuracy, Precision, Recall, Business reports
๐น 6. Exponents (Powers)
An exponent tells us how many times a number is multiplied by itself.
Example: 2ยณ = 2 ร 2 ร 2 = 8
More examples: 5ยฒ = 25, 10ยฒ = 100, 3โด = 81
๐น 7. Square Root
Square root is the opposite of squaring.
Example: โ49 = 7, โ100 = 10, โ144 = 12
Square roots are used in: Standard Deviation, Euclidean Distance, Machine Learning algorithms
๐น 8. Logarithms โญ
Logarithms are one of the most important mathematical concepts in Data Science.
A logarithm answers: "To what power should we raise a number to get another number?"
Example: logโ(8) = 3 because 2ยณ = 8
Another example: logโโ(1000) = 3 because 10ยณ = 1000
๐น 9. Why Logarithms Matter in Data Science?
Logarithms are used in:
โ Feature Engineering
โ Data Transformation
โ Loss Functions
โ Machine Learning Algorithms
โ Neural Networks
For example, if salary values range from โน10,000 to โน10,00,000, applying a logarithmic transformation reduces the range, making the data easier for some machine learning models to learn from.
๐น 10. Real-World Example
Suppose a company's revenue grows like this: 100, 1,000, 10,000, 100,000, 1,000,000
This range is very large.
Using logarithms it becomes: 2, 3, 4, 5, 6
The data becomes much easier to visualize and analyze.
๐น 11. Common Mistakes
โ Ignoring the order of operations.
Example: 5 + 2 ร 3
Correct answer: 11
โ Confusing percentages with decimals.
Remember: 0.25 = 25%, 0.50 = 50%, 1.00 = 100%
๐ฏ Practice Questions
1. Calculate 25 + 15 ร 2.
2. Convert 7/8 into a decimal.
3. Convert 0.45 into a percentage.
4. Find the value of 6ยฒ.
5. What is logโโ(100)?
๐ฏ Key Takeaways
โ Arithmetic forms the foundation of mathematics.
โ Always follow the BODMAS/PEMDAS rule.
โ Fractions, decimals, and percentages are interchangeable representations.
โ Exponents represent repeated multiplication.
โ Square roots are widely used in statistics and machine learning.
โ Logarithms help transform large numerical values and are commonly used in Data Science and Machine Learning.
Double Tap โค๏ธ For More
๐ Phase 2: Mathematics for Data Science
๐ Topic 1: Basic Mathematics (Arithmetic, Fractions, Exponents & Logarithms)
Now it's time to build the mathematical foundation behind Machine Learning and Artificial Intelligence.
๐น 1. Why Mathematics is Important in Data Science?
Mathematics helps Data Scientists:
โ Understand Machine Learning algorithms
โ Analyze data correctly
โ Optimize models
โ Measure performance
Without mathematics, it becomes difficult to understand how models learn from data.
๐น 2. Arithmetic Operations
Arithmetic is the foundation of all mathematical calculations.
The five basic operations are:
Addition: Symbol +
Example: 10 + 5 = 15
Subtraction: Symbol -
Example: 10 - 5 = 5
Multiplication: Symbol ร
Example: 10 ร 5 = 50
Division: Symbol รท
Example: 10 รท 5 = 2
Modulus: Symbol %
Example: 10 % 3 = 1
๐น 3. Order of Operations (BODMAS / PEMDAS)
When an expression contains multiple operations, follow this order:
1. Brackets ( )
2. Orders (Powers/Roots)
3. Division
4. Multiplication
5. Addition
6. Subtraction
Example: 5 + 2 ร 3
First perform multiplication: 2 ร 3 = 6
Then addition: 5 + 6 = 11
๐น 4. Fractions
A fraction represents a part of a whole.
Example: 3/4
Here: Numerator = 3, Denominator = 4
Converting Fractions to Decimals
Example: 3 รท 4 = 0.75
Converting Decimals to Percentages
Multiply by 100.
Example: 0.75 ร 100 = 75%
๐น 5. Percentages
Percentage means "per hundred."
Formula: Percentage = (Part / Total) ร 100
Example: A student scored 90 out of 120. (90 / 120) ร 100 = 75%
Percentages are widely used in: Accuracy, Precision, Recall, Business reports
๐น 6. Exponents (Powers)
An exponent tells us how many times a number is multiplied by itself.
Example: 2ยณ = 2 ร 2 ร 2 = 8
More examples: 5ยฒ = 25, 10ยฒ = 100, 3โด = 81
๐น 7. Square Root
Square root is the opposite of squaring.
Example: โ49 = 7, โ100 = 10, โ144 = 12
Square roots are used in: Standard Deviation, Euclidean Distance, Machine Learning algorithms
๐น 8. Logarithms โญ
Logarithms are one of the most important mathematical concepts in Data Science.
A logarithm answers: "To what power should we raise a number to get another number?"
Example: logโ(8) = 3 because 2ยณ = 8
Another example: logโโ(1000) = 3 because 10ยณ = 1000
๐น 9. Why Logarithms Matter in Data Science?
Logarithms are used in:
โ Feature Engineering
โ Data Transformation
โ Loss Functions
โ Machine Learning Algorithms
โ Neural Networks
For example, if salary values range from โน10,000 to โน10,00,000, applying a logarithmic transformation reduces the range, making the data easier for some machine learning models to learn from.
๐น 10. Real-World Example
Suppose a company's revenue grows like this: 100, 1,000, 10,000, 100,000, 1,000,000
This range is very large.
Using logarithms it becomes: 2, 3, 4, 5, 6
The data becomes much easier to visualize and analyze.
๐น 11. Common Mistakes
โ Ignoring the order of operations.
Example: 5 + 2 ร 3
Correct answer: 11
โ Confusing percentages with decimals.
Remember: 0.25 = 25%, 0.50 = 50%, 1.00 = 100%
๐ฏ Practice Questions
1. Calculate 25 + 15 ร 2.
2. Convert 7/8 into a decimal.
3. Convert 0.45 into a percentage.
4. Find the value of 6ยฒ.
5. What is logโโ(100)?
๐ฏ Key Takeaways
โ Arithmetic forms the foundation of mathematics.
โ Always follow the BODMAS/PEMDAS rule.
โ Fractions, decimals, and percentages are interchangeable representations.
โ Exponents represent repeated multiplication.
โ Square roots are widely used in statistics and machine learning.
โ Logarithms help transform large numerical values and are commonly used in Data Science and Machine Learning.
Double Tap โค๏ธ For More
โค12๐คฉ1
๐ ๐ ๐ฎ๐๐๐ฒ๐ฟ ๐๐ป-๐๐ฒ๐บ๐ฎ๐ป๐ฑ ๐ฆ๐ธ๐ถ๐น๐น๐ ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐! ๐ป๐ฅ
Want to future-proof your career without spending a single rupee? These 4 beginner-friendly FREE courses will help you build practical, job-ready skills
๐ FREE Courses Included
๐ Business Intelligence Using Excel
๐ค Generative AI for Beginners
๐ป C Programming for Beginners
๐ซ Python Interview Questions & Answers
๐๐ป๐ฟ๐ผ๐น๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐๐:-
https://pdlink.in/4hSgTuW
๐ฅ Don't waitโstart learning today and unlock better career opportunities!
Want to future-proof your career without spending a single rupee? These 4 beginner-friendly FREE courses will help you build practical, job-ready skills
๐ FREE Courses Included
๐ Business Intelligence Using Excel
๐ค Generative AI for Beginners
๐ป C Programming for Beginners
๐ซ Python Interview Questions & Answers
๐๐ป๐ฟ๐ผ๐น๐น ๐๐ผ๐ฟ ๐๐ฅ๐๐๐:-
https://pdlink.in/4hSgTuW
๐ฅ Don't waitโstart learning today and unlock better career opportunities!
โค2