Python Roadmap
https://www.linkedin.com/posts/sql-analysts_python-learning-plan-in-2024-week-1-activity-7234041944056754176-yrT-
Like for more
https://www.linkedin.com/posts/sql-analysts_python-learning-plan-in-2024-week-1-activity-7234041944056754176-yrT-
Like for more
โค2
Python Tip for the day:
Use the "enumerate" function to iterate over a sequence and get the index of each element.
Sometimes when you're iterating over a list or other sequence in Python, you need to keep track of the index of the current element. One way to do this is to use a counter variable and increment it on each iteration, but this can be tedious and error-prone.
A better way to get the index of each element is to use the built-in "enumerate" function. The "enumerate" function takes an iterable (such as a list or tuple) as its argument and returns a sequence of (index, value) tuples, where "index" is the index of the current element and "value" is the value of the current element. Here's an example:
The output of this code would be:
Use the "enumerate" function to iterate over a sequence and get the index of each element.
Sometimes when you're iterating over a list or other sequence in Python, you need to keep track of the index of the current element. One way to do this is to use a counter variable and increment it on each iteration, but this can be tedious and error-prone.
A better way to get the index of each element is to use the built-in "enumerate" function. The "enumerate" function takes an iterable (such as a list or tuple) as its argument and returns a sequence of (index, value) tuples, where "index" is the index of the current element and "value" is the value of the current element. Here's an example:
Iterate over a list of strings and print each string with its indexIn this example, we use the "enumerate" function to iterate over a list of strings. On each iteration, the "enumerate" function returns a tuple containing the index of the current string and the string itself. We use tuple unpacking to assign these values to the variables "i" and "s", and then print out the index and string on a separate line.
strings = ['apple', 'banana', 'cherry', 'date']
for i, s in enumerate(strings):
print(f"{i}: {s}")
The output of this code would be:
appleUsing the "enumerate" function can make your code more concise and easier to read, especially when you need to keep track of the index of each element in a sequence.
1: banana
2: cherry
3: date
๐12
Forwarded from Free Courses with Certificate - Python Programming, Data Science, Java Coding, SQL, Web Development, AI, ML, ChatGPT Expert
Many people reached out to me saying telegram may get banned in their countries. So I've decided to create WhatsApp channels based on your interests ๐๐
Free Courses with Certificate: https://whatsapp.com/channel/0029Vamhzk5JENy1Zg9KmO2g
Jobs & Internship Opportunities:
https://whatsapp.com/channel/0029VaI5CV93AzNUiZ5Tt226
Web Development: https://whatsapp.com/channel/0029VaiSdWu4NVis9yNEE72z
Python Free Books & Projects: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L
Java Resources: https://whatsapp.com/channel/0029VamdH5mHAdNMHMSBwg1s
Coding Interviews: https://whatsapp.com/channel/0029VammZijATRSlLxywEC3X
SQL: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
Power BI: https://whatsapp.com/channel/0029Vai1xKf1dAvuk6s1v22c
Programming Free Resources: https://whatsapp.com/channel/0029VahiFZQ4o7qN54LTzB17
Data Science Projects: https://whatsapp.com/channel/0029Va4QUHa6rsQjhITHK82y
Learn Data Science & Machine Learning: https://whatsapp.com/channel/0029Va8v3eo1NCrQfGMseL2D
Donโt worry Guys your contact number will stay hidden!
ENJOY LEARNING ๐๐
Free Courses with Certificate: https://whatsapp.com/channel/0029Vamhzk5JENy1Zg9KmO2g
Jobs & Internship Opportunities:
https://whatsapp.com/channel/0029VaI5CV93AzNUiZ5Tt226
Web Development: https://whatsapp.com/channel/0029VaiSdWu4NVis9yNEE72z
Python Free Books & Projects: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L
Java Resources: https://whatsapp.com/channel/0029VamdH5mHAdNMHMSBwg1s
Coding Interviews: https://whatsapp.com/channel/0029VammZijATRSlLxywEC3X
SQL: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
Power BI: https://whatsapp.com/channel/0029Vai1xKf1dAvuk6s1v22c
Programming Free Resources: https://whatsapp.com/channel/0029VahiFZQ4o7qN54LTzB17
Data Science Projects: https://whatsapp.com/channel/0029Va4QUHa6rsQjhITHK82y
Learn Data Science & Machine Learning: https://whatsapp.com/channel/0029Va8v3eo1NCrQfGMseL2D
Donโt worry Guys your contact number will stay hidden!
ENJOY LEARNING ๐๐
๐15โค5
Easy Python scenarios for everyday data tasks
Scenario 1: Data Cleaning
Question:
You have a DataFrame containing product prices with columns Product and Price. Some of the prices are stored as strings with a dollar sign, like $10. Write a Python function to convert the prices to float.
Answer:
import pandas as pd
data = {
'Product': ['A', 'B', 'C', 'D'],
'Price': ['$10', '$20', '$30', '$40']
}
df = pd.DataFrame(data)
def clean_prices(df):
df['Price'] = df['Price'].str.replace('$', '').astype(float)
return df
cleaned_df = clean_prices(df)
print(cleaned_df)
Scenario 2: Basic Aggregation
Question:
You have a DataFrame containing sales data with columns Region and Sales. Write a Python function to calculate the total sales for each region.
Answer:
import pandas as pd
data = {
'Region': ['North', 'South', 'East', 'West', 'North', 'South', 'East', 'West'],
'Sales': [100, 200, 150, 250, 300, 100, 200, 150]
}
df = pd.DataFrame(data)
def total_sales_per_region(df):
total_sales = df.groupby('Region')['Sales'].sum().reset_index()
return total_sales
total_sales = total_sales_per_region(df)
print(total_sales)
Scenario 3: Filtering Data
Question:
You have a DataFrame containing customer data with columns โCustomerIDโ, Name, and Age. Write a Python function to filter out customers who are younger than 18 years old.
Answer:
import pandas as pd
data = {
'CustomerID': [1, 2, 3, 4, 5],
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'Age': [17, 22, 15, 35, 40]
}
df = pd.DataFrame(data)
def filter_customers(df):
filtered_df = df[df['Age'] >= 18]
return filtered_df
filtered_customers = filter_customers(df)
print(filtered_customers)
Scenario 1: Data Cleaning
Question:
You have a DataFrame containing product prices with columns Product and Price. Some of the prices are stored as strings with a dollar sign, like $10. Write a Python function to convert the prices to float.
Answer:
import pandas as pd
data = {
'Product': ['A', 'B', 'C', 'D'],
'Price': ['$10', '$20', '$30', '$40']
}
df = pd.DataFrame(data)
def clean_prices(df):
df['Price'] = df['Price'].str.replace('$', '').astype(float)
return df
cleaned_df = clean_prices(df)
print(cleaned_df)
Scenario 2: Basic Aggregation
Question:
You have a DataFrame containing sales data with columns Region and Sales. Write a Python function to calculate the total sales for each region.
Answer:
import pandas as pd
data = {
'Region': ['North', 'South', 'East', 'West', 'North', 'South', 'East', 'West'],
'Sales': [100, 200, 150, 250, 300, 100, 200, 150]
}
df = pd.DataFrame(data)
def total_sales_per_region(df):
total_sales = df.groupby('Region')['Sales'].sum().reset_index()
return total_sales
total_sales = total_sales_per_region(df)
print(total_sales)
Scenario 3: Filtering Data
Question:
You have a DataFrame containing customer data with columns โCustomerIDโ, Name, and Age. Write a Python function to filter out customers who are younger than 18 years old.
Answer:
import pandas as pd
data = {
'CustomerID': [1, 2, 3, 4, 5],
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'Age': [17, 22, 15, 35, 40]
}
df = pd.DataFrame(data)
def filter_customers(df):
filtered_df = df[df['Age'] >= 18]
return filtered_df
filtered_customers = filter_customers(df)
print(filtered_customers)
๐20โค3
So as a beginner you may Python as first language.
To learn this language, I divided it into 5 parts.
1. Basics:
- Syntax
- Data types
- Variables
- Control structures
- Functions
2. Data Structures:
- Lists
- Tuples
- Dictionaries
- Sets
3. File Input/Output:
- Reading from files
- Writing to files
4. Modules and Packages:
- Importing modules
- Creating modules
5. Object-Oriented Programming:
- Classes
- Objects
- Inheritance
If anything left please comment ๐
I have curated the best interview resources to crack Python Interviews ๐๐
https://whatsapp.com/channel/0029VaGgzAk72WTmQFERKh02
Hope you'll like it
Like this post if you need more resources like this ๐โค๏ธ
To learn this language, I divided it into 5 parts.
1. Basics:
- Syntax
- Data types
- Variables
- Control structures
- Functions
2. Data Structures:
- Lists
- Tuples
- Dictionaries
- Sets
3. File Input/Output:
- Reading from files
- Writing to files
4. Modules and Packages:
- Importing modules
- Creating modules
5. Object-Oriented Programming:
- Classes
- Objects
- Inheritance
If anything left please comment ๐
I have curated the best interview resources to crack Python Interviews ๐๐
https://whatsapp.com/channel/0029VaGgzAk72WTmQFERKh02
Hope you'll like it
Like this post if you need more resources like this ๐โค๏ธ
๐19โค3
Many people reached out to me saying telegram may get banned in their countries. So I've decided to create WhatsApp channels based on your interests ๐๐
Free Courses with Certificate: https://whatsapp.com/channel/0029Vamhzk5JENy1Zg9KmO2g
Jobs & Internship Opportunities:
https://whatsapp.com/channel/0029VaI5CV93AzNUiZ5Tt226
Web Development: https://whatsapp.com/channel/0029VaiSdWu4NVis9yNEE72z
Python Free Books & Projects: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L
Java Resources: https://whatsapp.com/channel/0029VamdH5mHAdNMHMSBwg1s
Coding Interviews: https://whatsapp.com/channel/0029VammZijATRSlLxywEC3X
SQL: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
Power BI: https://whatsapp.com/channel/0029Vai1xKf1dAvuk6s1v22c
Programming Free Resources: https://whatsapp.com/channel/0029VahiFZQ4o7qN54LTzB17
Data Science Projects: https://whatsapp.com/channel/0029Va4QUHa6rsQjhITHK82y
Learn Data Science & Machine Learning: https://whatsapp.com/channel/0029Va8v3eo1NCrQfGMseL2D
Donโt worry Guys your contact number will stay hidden!
ENJOY LEARNING ๐๐
Free Courses with Certificate: https://whatsapp.com/channel/0029Vamhzk5JENy1Zg9KmO2g
Jobs & Internship Opportunities:
https://whatsapp.com/channel/0029VaI5CV93AzNUiZ5Tt226
Web Development: https://whatsapp.com/channel/0029VaiSdWu4NVis9yNEE72z
Python Free Books & Projects: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L
Java Resources: https://whatsapp.com/channel/0029VamdH5mHAdNMHMSBwg1s
Coding Interviews: https://whatsapp.com/channel/0029VammZijATRSlLxywEC3X
SQL: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v
Power BI: https://whatsapp.com/channel/0029Vai1xKf1dAvuk6s1v22c
Programming Free Resources: https://whatsapp.com/channel/0029VahiFZQ4o7qN54LTzB17
Data Science Projects: https://whatsapp.com/channel/0029Va4QUHa6rsQjhITHK82y
Learn Data Science & Machine Learning: https://whatsapp.com/channel/0029Va8v3eo1NCrQfGMseL2D
Donโt worry Guys your contact number will stay hidden!
ENJOY LEARNING ๐๐
๐19๐คฃ2โค1
๐ 9 must-have Python developer tools.
1. PyCharm IDE
2. Jupyter notebook
3. Keras
4. Pip Package
5. Python Anywhere
6. Scikit-Learn
7. Sphinx
8. Selenium
9. Sublime Text
1. PyCharm IDE
2. Jupyter notebook
3. Keras
4. Pip Package
5. Python Anywhere
6. Scikit-Learn
7. Sphinx
8. Selenium
9. Sublime Text
๐13โค4
15 Best Project Ideas for Python : ๐
๐ Beginner Level:
1. Simple Calculator
2. To-Do List
3. Number Guessing Game
4. Dice Rolling Simulator
5. Word Counter
๐ Intermediate Level:
6. Weather App
7. URL Shortener
8. Movie Recommender System
9. Chatbot
10. Image Caption Generator
๐ Advanced Level:
11. Stock Market Analysis
12. Autonomous Drone Control
13. Music Genre Classification
14. Real-Time Object Detection
15. Natural Language Processing (NLP) Sentiment Analysis
๐ Beginner Level:
1. Simple Calculator
2. To-Do List
3. Number Guessing Game
4. Dice Rolling Simulator
5. Word Counter
๐ Intermediate Level:
6. Weather App
7. URL Shortener
8. Movie Recommender System
9. Chatbot
10. Image Caption Generator
๐ Advanced Level:
11. Stock Market Analysis
12. Autonomous Drone Control
13. Music Genre Classification
14. Real-Time Object Detection
15. Natural Language Processing (NLP) Sentiment Analysis
๐27โค4๐ฅ4๐1
10 Ways to Speed Up Your Python Code
1. List Comprehensions
numbers = [x**2 for x in range(100000) if x % 2 == 0]
instead of
numbers = []
for x in range(100000):
if x % 2 == 0:
numbers.append(x**2)
2. Use the Built-In Functions
Many of Pythonโs built-in functions are written in C, which makes them much faster than a pure python solution.
3. Function Calls Are Expensive
Function calls are expensive in Python. While it is often good practice to separate code into functions, there are times where you should be cautious about calling functions from inside of a loop. It is better to iterate inside a function than to iterate and call a function each iteration.
4. Lazy Module Importing
If you want to use the time.sleep() function in your code, you don't necessarily need to import the entire time package. Instead, you can just do from time import sleep and avoid the overhead of loading basically everything.
5. Take Advantage of Numpy
Numpy is a highly optimized library built with C. It is almost always faster to offload complex math to Numpy rather than relying on the Python interpreter.
6. Try Multiprocessing
Multiprocessing can bring large performance increases to a Python script, but it can be difficult to implement properly compared to other methods mentioned in this post.
7. Be Careful with Bulky Libraries
One of the advantages Python has over other programming languages is the rich selection of third-party libraries available to developers. But, what we may not always consider is the size of the library we are using as a dependency, which could actually decrease the performance of your Python code.
8. Avoid Global Variables
Python is slightly faster at retrieving local variables than global ones. It is simply best to avoid global variables when possible.
9. Try Multiple Solutions
Being able to solve a problem in multiple ways is nice. But, there is often a solution that is faster than the rest and sometimes it comes down to just using a different method or data structure.
10. Think About Your Data Structures
Searching a dictionary or set is insanely fast, but lists take time proportional to the length of the list. However, sets and dictionaries do not maintain order. If you care about the order of your data, you canโt make use of dictionaries or sets.
1. List Comprehensions
numbers = [x**2 for x in range(100000) if x % 2 == 0]
instead of
numbers = []
for x in range(100000):
if x % 2 == 0:
numbers.append(x**2)
2. Use the Built-In Functions
Many of Pythonโs built-in functions are written in C, which makes them much faster than a pure python solution.
3. Function Calls Are Expensive
Function calls are expensive in Python. While it is often good practice to separate code into functions, there are times where you should be cautious about calling functions from inside of a loop. It is better to iterate inside a function than to iterate and call a function each iteration.
4. Lazy Module Importing
If you want to use the time.sleep() function in your code, you don't necessarily need to import the entire time package. Instead, you can just do from time import sleep and avoid the overhead of loading basically everything.
5. Take Advantage of Numpy
Numpy is a highly optimized library built with C. It is almost always faster to offload complex math to Numpy rather than relying on the Python interpreter.
6. Try Multiprocessing
Multiprocessing can bring large performance increases to a Python script, but it can be difficult to implement properly compared to other methods mentioned in this post.
7. Be Careful with Bulky Libraries
One of the advantages Python has over other programming languages is the rich selection of third-party libraries available to developers. But, what we may not always consider is the size of the library we are using as a dependency, which could actually decrease the performance of your Python code.
8. Avoid Global Variables
Python is slightly faster at retrieving local variables than global ones. It is simply best to avoid global variables when possible.
9. Try Multiple Solutions
Being able to solve a problem in multiple ways is nice. But, there is often a solution that is faster than the rest and sometimes it comes down to just using a different method or data structure.
10. Think About Your Data Structures
Searching a dictionary or set is insanely fast, but lists take time proportional to the length of the list. However, sets and dictionaries do not maintain order. If you care about the order of your data, you canโt make use of dictionaries or sets.
๐14โค7
TOP 10 Python Concepts for Job Interview
1. Reading data from file/table
2. Writing data to file/table
3. Data Types
4. Function
5. Data Preprocessing (numpy/pandas)
6. Data Visualisation (Matplotlib/seaborn/bokeh)
7. Machine Learning (sklearn)
8. Deep Learning (Tensorflow/Keras/PyTorch)
9. Distributed Processing (PySpark)
10. Functional and Object Oriented Programming
1. Reading data from file/table
2. Writing data to file/table
3. Data Types
4. Function
5. Data Preprocessing (numpy/pandas)
6. Data Visualisation (Matplotlib/seaborn/bokeh)
7. Machine Learning (sklearn)
8. Deep Learning (Tensorflow/Keras/PyTorch)
9. Distributed Processing (PySpark)
10. Functional and Object Oriented Programming
๐22๐ซก2
โจ๏ธ Asynchronous code
Asynchronous code is an approach to writing code that allows multiple tasks to be performed simultaneously within a single process. This is achieved through the use of asynchronous functions and coroutines. Unlike synchronous code, which executes each task sequentially, asynchronous code can run multiple tasks โin parallelโ and organize their execution using iterations and callback calls.
๐8โค3๐ค1