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 Tools
Machine Learning
Machine Learning & AI
Machine Learning Tools
Manage Data
MLOps
Natural Language Processing
NumPy
Pandas
Polars
PySpark
Python Helpers
Python Tips
Python Utilities
Scrape Data
SQL
Testing
Time Series
Tools
Visualization
Visualization & Reporting
Workflow & Automation
Workflow Automation

Python Tips

Apply a function on multiple data within a directory

Have you ever wanted to apply a function on multiple data within a directory? Instead of manually typing different data’s name, why don’t we loop through all the data in that directory? Below is the code snippet for exactly that
This is especially useful when you need to apply one function to more than 5 data. Now, all we need to do is to run, for example,
python <a href="http://process.py/" data-attribute-index="2">process.py</a>
to apply one script to multiple data!
Favorite

Apply a function on multiple data within a directory Read More »

Static method: use the function without adding the attributes required for a new instance

Have you ever had a function in your class that doesn’t access any properties of a class but makes sense that it belongs to the class? You might find it redundant to instantiate the class to use that function. That is when you can turn your function into a static method.
All you need to turn your function into a static method is the decorator ‘@staticmethod’. Now you can use the function without adding the attributes required for a new instance. Find the example below.
Favorite

Static method: use the function without adding the attributes required for a new instance Read More »

Compare the execution time between 2 functions

If you want to compare the execution time between 2 functions, the easiest method to measure the time is timeit.timeit. You can also specify the number of times you want to rerun your function to get a better estimation of the time. Below is the code
Something you might not know: it is faster to use list range than to use list comprehension.
Favorite

Compare the execution time between 2 functions Read More »

0
    0
    Your Cart
    Your cart is empty
    Scroll to Top

    Work with Khuyen Tran

    Work with Khuyen Tran