Data Science & Machine Learning
77.1K subscribers
857 photos
68 files
771 links
Join this channel to learn data science, artificial intelligence and machine learning with funny quizzes, interesting projects and amazing resources for free

For collaborations: @love_data
Download Telegram
๐Ÿš€ 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 calculator.py

def 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.0

Import Specific Functions

from math import sqrt
print(sqrt(49))


Output: 7.0

Import 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.
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.๐Ÿƒโ€โ™‚๏ธ
โค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"
๐Ÿ“Š ๐——๐—ฎ๐˜๐—ฎ ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€ ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—ป๐˜€๐—ต๐—ถ๐—ฝ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ ๐Ÿš€

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
โค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
โค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!
โค2
๐Ÿฏ ๐—ง๐—ผ๐—ฝ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ | ๐—•๐—ผ๐—ผ๐—ธ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ป๐˜€๐—ฒ๐—น๐—น๐—ถ๐—ป๐—ด ๐—ฆ๐—ฒ๐˜€๐˜€๐—ถ๐—ผ๐—ป ๐—œ๐—ป ๐—–๐—ต๐—ฒ๐—ป๐—ป๐—ฎ๐—ถ๐Ÿ˜
โ€‹
Learnfrom India's Best Mentors , Get 100% Placement Assistance

๐Ÿ’ซData Analytics :- https://pdlink.in/4q59ef1
โ€‹
๐Ÿ’ซFullstack :- https://pdlink.in/4he12a2
โ€‹
๐Ÿ’ซAI :- https://pdlink.in/4he5mpO
โ€‹
In Today's competitive world, you need industry-relevant skills taught by the best.
โค1
Essential Python Libraries to build your career in Data Science ๐Ÿ“Š๐Ÿ‘‡

1. NumPy:
- Efficient numerical operations and array manipulation.

2. Pandas:
- Data manipulation and analysis with powerful data structures (DataFrame, Series).

3. Matplotlib:
- 2D plotting library for creating visualizations.

4. Seaborn:
- Statistical data visualization built on top of Matplotlib.

5. Scikit-learn:
- Machine learning toolkit for classification, regression, clustering, etc.

6. TensorFlow:
- Open-source machine learning framework for building and deploying ML models.

7. PyTorch:
- Deep learning library, particularly popular for neural network research.

8. SciPy:
- Library for scientific and technical computing.

9. Statsmodels:
- Statistical modeling and econometrics in Python.

10. NLTK (Natural Language Toolkit):
- Tools for working with human language data (text).

11. Gensim:
- Topic modeling and document similarity analysis.

12. Keras:
- High-level neural networks API, running on top of TensorFlow.

13. Plotly:
- Interactive graphing library for making interactive plots.

14. Beautiful Soup:
- Web scraping library for pulling data out of HTML and XML files.

15. OpenCV:
- Library for computer vision tasks.

As a beginner, you can start with Pandas and NumPy for data manipulation and analysis. For data visualization, Matplotlib and Seaborn are great starting points. As you progress, you can explore machine learning with Scikit-learn, TensorFlow, and PyTorch.

Free Notes & Books to learn Data Science: https://t.me/datasciencefree

Python Project Ideas: https://t.me/dsabooks/85

Best Resources to learn Python & Data Science ๐Ÿ‘‡๐Ÿ‘‡

Python Tutorial

Data Science Course by Kaggle

Machine Learning Course by Google

Best Data Science & Machine Learning Resources

Interview Process for Data Science Role at Amazon

Python Interview Resources

Join @free4unow_backup for more free courses

Like for more โค๏ธ

ENJOY LEARNING๐Ÿ‘๐Ÿ‘
โค5๐Ÿ‘2
๐Ÿš€ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—”๐—œ ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜ | ๐Ÿฑ ๐— ๐˜‚๐˜€๐˜-๐—ง๐—ฎ๐—ธ๐—ฒ ๐—š๐—ผ๐—ผ๐—ด๐—น๐—ฒ ๐—”๐—œ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐Ÿ”ฅ

Artificial Intelligence is transforming every industryโ€”and now you can learn directly from Google with 100% FREE AI courses!

๐ŸŽฏ Perfect For
๐ŸŽ“ Students & Freshers
๐Ÿ‘จโ€๐Ÿ’ป Software Developers
๐Ÿ“Š Data Analysts
๐Ÿ’ซ AI & Machine Learning Aspirants
๐Ÿ’ผ Working Professionals

๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:- 

https://pdlink.in/45HWa5Q

๐Ÿ”ฅ Start your AI journey today and stay ahead in the era of Artificial Intelligence!
โค1
Find the Mean of the following dataset:
10, 20, 30, 40, 50
Anonymous Quiz
4%
20
89%
30
4%
40
4%
25
โค2
What is the Median of the following dataset?
5, 10, 15, 20, 25
Anonymous Quiz
82%
15
6%
20
5%
10
7%
17.5
โค2
What is the Mode of the following dataset?
2, 4, 4, 5, 6, 6, 6, 8
Anonymous Quiz
6%
2
7%
4
10%
5
76%
6
โค4๐Ÿ˜1
Which measure of central tendency is least affected by outliers?
Anonymous Quiz
13%
A) Mean
44%
B) Median
25%
C) Mode
17%
D) Range
โค3
๐Ÿš€ ๐Ÿฐ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐—ง๐—ผ ๐—•๐—ผ๐—ผ๐˜€๐˜ ๐—ฌ๐—ผ๐˜‚๐—ฟ ๐—ฅ๐—ฒ๐˜€๐˜‚๐—บ๐—ฒ๐Ÿ”ฅ

Add these 100% FREE certification courses to your resume and gain valuable, job-ready skills that employers look for.

โœ… 100% FREE Certification Courses
โœ… Beginner-Friendly Learning
โœ… Industry-Relevant Skills
โœ… Self-Paced Online Learning
โœ… Strengthen Your Resume & LinkedIn Profile
โœ… Improve Your Job & Internship Opportunities

๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:- 

https://pdlink.in/4bwkOtA

๐Ÿ”ฅ Invest in your skills today and give your resume the competitive edge it deserves!
โค2
๐Ÿš€ Data Science Roadmap 2026

๐Ÿ“˜ Phase 2: Mathematics for Data Science

๐Ÿ“– Topic 3: Variance & Standard Deviation

Welcome back! ๐Ÿ‘‹

In the previous lesson, you learned about Mean, Median, and Mode, which help us find the center of a dataset.

But knowing the average alone is not enough.

Imagine these two datasets:

Dataset A

40, 45, 50, 55, 60

Dataset B

10, 20, 50, 80, 90

Both datasets have the same mean (50), but they are very different.

โ€ข Dataset A has values close to the mean.

โ€ข Dataset B has values spread far away from the mean.

To measure this spread, we use Variance and Standard Deviation.

These are among the most important statistical concepts in Data Science and Machine Learning.

๐Ÿ”น 1. What is Variance?

Variance measures how far each value is from the mean.

โ€ข Small variance โ†’ Data points are close together.

โ€ข Large variance โ†’ Data points are widely spread.

Formula (Population Variance)

Variance = ฮฃ(x โˆ’ Mean)ยฒ / N

Where:

โ€ข ฮฃ = Sum

โ€ข x = Each data point

โ€ข Mean = Average

โ€ข N = Total number of observations

๐Ÿ”น 2. Example of Variance

Dataset: 10, 20, 30

Step 1: Find the Mean

(10 + 20 + 30) / 3 = 20

Step 2: Find the Difference from the Mean

10 โˆ’ 20 = -10

20 โˆ’ 20 = 0

30 โˆ’ 20 = 10

Step 3: Square the Differences

100, 0, 100

Step 4: Calculate Variance

(100 + 0 + 100) / 3 = 66.67

๐Ÿ”น 3. What is Standard Deviation? โญ

Standard Deviation (SD) is simply the square root of the variance.

Formula

Standard Deviation = โˆšVariance

Using the previous example:

Variance = 66.67

SD = โˆš66.67 โ‰ˆ 8.16

๐Ÿ”น 4. Why Standard Deviation is Preferred?

Variance is measured in squared units, making it harder to interpret.

Standard Deviation is measured in the same units as the original data, making it easier to understand.

Example:

If salaries are measured in rupees:

โ€ข Variance โ†’ Rupeesยฒ โŒ

โ€ข Standard Deviation โ†’ Rupees โœ…

๐Ÿ”น 5. Python Example

Using the "statistics" module:

import statistics

numbers = [10, 20, 30]

print(statistics.pvariance(numbers))
print(statistics.pstdev(numbers))
โค4๐Ÿ‘2