Scripting

How to Execute a Python File with Arguments in Python?

Problem: You have a Python code file script.py and you want to run it in your Python shell with arguments. Example: You seek a function execute(“script.py”, arg1, arg2, …). The arguments arg1, arg2, … should be used within script.py. How to execute the Python file within your Python code by passing the arguments to the …

How to Execute a Python File with Arguments in Python? Read More »

Python enumerate() — A Simple Illustrated Guide with Video

If you’re like me, you want to come to the heart of an issue fast. Here’s the 1-paragraph summary of the enumerate() function—that’s all you need to know to get started using it: Python’s built-in enumerate(iterable) function allows you to loop over all elements in an iterable and their associated counters. Formally, it takes an …

Python enumerate() — A Simple Illustrated Guide with Video Read More »

Matplotlib Widgets — Creating Interactive Plots with Sliders

This article describes how to generate interactive plots by using the .widgets package from the matplotlib library. As can be inferred from the name, the .widgets package allows creating different types of interactive buttons, which can be used for modifying what is displayed in a matplotlib graph. In particular, this article will focus on the …

Matplotlib Widgets — Creating Interactive Plots with Sliders Read More »

Python dir() — A Simple Guide with Video

If used without argument, Python’s built-in dir() function returns the function and variable names defined in the local scope—the namespace of your current module. If used with an object argument, dir(object) returns a list of attribute and method names defined in the object’s scope. Thus, dir() returns all names in a given scope. Usage Learn …

Python dir() — A Simple Guide with Video Read More »

Python dict() — A Simple Guide with Video

Python’s built-in dict() function creates and returns a new dictionary object from the comma-separated argument list of key = value mappings. For example, dict(name = ‘Alice’, age = 22, profession = ‘programmer’) creates a dictionary with three mappings: {‘name’: ‘Alice’, ‘age’: 22, ‘profession’: ‘programmer’}. A dictionary is an unordered and mutable data structure, so it …

Python dict() — A Simple Guide with Video Read More »

Python Scipy signal.find_peaks() — A Helpful Guide

This article deals with the analysis and processing of signals, more specifically on how to identify and calculate the peaks contained in a given signal. Motivation Being able to identify and hence work with the peaks of a signal is of fundamental importance in lots of different fields, from electronics to data science and economics. …

Python Scipy signal.find_peaks() — A Helpful Guide Read More »

Python Join Arguments and String Concatenation

Problem: Write a function that joins an arbitrary number of string arguments with a given separator. Example: Given the string arguments “A”, “B”, and “C” and the string separator “-“. Join them to the concatenated string “A-B-C”. Solution: The following code creates a Python function concat() that takes an arbitrary number of arguments, packs them …

Python Join Arguments and String Concatenation Read More »

Python getattr()

Python’s built-in getattr(object, string) function returns the value of the object‘s attribute with name string. If this doesn’t exist, it returns the value provided as an optional third default argument. If that doesn’t exist either, it raises an AttributeError. An example is getattr(porsche, ‘speed’) which is equivalent to porsche.speed. Usage Learn by example! Here’s an …

Python getattr() Read More »

Creating Beautiful Heatmaps with Seaborn

Heatmaps are a specific type of plot which exploits the combination of color schemes and numerical values for representing complex and articulated datasets. They are largely used in data science application that involves large numbers, like biology, economics and medicine. In this video we will see how to create a heatmap for representing the total …

Creating Beautiful Heatmaps with Seaborn Read More »