Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
About Article
Analyze Data
Archive
Best Practices
Better Outputs
Blog
Code Optimization
Code Quality
Command Line
Daily tips
Dashboard
Data Analysis & Manipulation
Data Engineer
Data Visualization
DataFrame
Delta Lake
DevOps
DuckDB
Environment Management
Feature Engineer
Git
Jupyter Notebook
LLM
LLM
Machine Learning
Machine Learning
Machine Learning & AI
Manage Data
MLOps
Natural Language Processing
NumPy
Pandas
Polars
PySpark
Python Tips
Python Utilities
Python Utilities
Scrape Data
SQL
Testing
Time Series
Tools
Visualization
Visualization & Reporting
Workflow & Automation
Workflow Automation

Code Optimization

Speed Up Your Python Code with Concurrency

If you want to speed up the execution of functions that are not related to each other, you might consider running your code concurrently. Concurrency refers to a system that can do more than one thing simultaneously.

To run your code concurrently with a little additional code, simply add the @task and @flow decorators from Prefect.

Link to Prefect.
Favorite

Speed Up Your Python Code with Concurrency Read More »

pyinstrument: Readable Python Profiler

Have you ever wanted to get statistics of how long various parts of your code are executed to optimize your code? profile and CProfile allow you to profile your code, but the outputs are long and hard to understand, especially when using high-level libraries like pandas.
You can get a more readable output using pyinstrument. The code below shows how pyinstrument works.
Link to pyinstrument.

Find other tips to speed up and track your code here.
Favorite

pyinstrument: Readable Python Profiler Read More »

interrogate: Check your Python Code for Missing Docstrings.

Sometimes, you might forget to write docstrings for classes and functions. Instead of manually looking at all your functions and classes for missing docstrings, use interrogate instead.
In the code above, I use interrogate to check for missing docstrings in the file main.py.
To automatically check for missing docstrings whenever you commit new files, add interrogate to your pre-commit hooks. Here is how to do that.
Link to interrogate.
Link to the source code. Favorite

interrogate: Check your Python Code for Missing Docstrings. Read More »

pre-commit hooks: Automate Python Code Cleaning

If you want to automatically format your code, check if your code’s compliance with PEP8, and sort your imports before committing your files, use pre-commit hooks.
If all files are in the right format, the commit will be made. Otherwise, the commit will be denied.
I use pre-commit hooks for most of my projects to maintain code quality standards.
Here is the link to the article I found that shows you how to use pre-commit with black, flake8, and isort.Favorite

pre-commit hooks: Automate Python Code Cleaning Read More »

isort: Automatically Sort your Python Imports in 1 Line of Code

When your code grows bigger, you might need to import a lot of libraries, and it can be confusing to look at. Instead of manually organing your imports, use isort.
isort is a Python library to sort imports alphabetically and automatically separated into sections and by type. You just need to use isort name_of_your_file.py to sort your imports.
Above is how the imports are organized before and after sorting.
Find isort in this repository.Favorite

isort: Automatically Sort your Python Imports in 1 Line of Code Read More »

0
    0
    Your Cart
    Your cart is empty
    Scroll to Top

    Work with Khuyen Tran

    Work with Khuyen Tran