Data Science & Machine Learning
75.2K subscribers
816 photos
68 files
722 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
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:

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"])
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)
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: 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
Which mode is used to read a file?
Anonymous Quiz
5%
A) "w"
3%
B) "a"
87%
C) "r"
5%
D) "rw"
❀2
What will the following code do?

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
❀2πŸ‘1πŸ₯°1
Top Programming Languages for Beginners πŸ‘†
❀5πŸ‘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:
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.
❀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:
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
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)
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())
Anonymous Quiz
64%
A) 20
25%
B) 30
6%
C) 10
5%
D) Error
❀4