How-to articles, tricks, and solutions about PYTHON
Replacements for switch statement in Python?
Here are a few alternatives to using a switch statement in Python:
Reverse / invert a dictionary mapping
Here's an example of how you can reverse or invert a dictionary mapping in Python:
Running shell command and capturing the output
In Python, you can use the subprocess module to run shell commands and capture their output.
Save plot to image file instead of displaying it using Matplotlib
To save a plot to an image file using Matplotlib, you can use the savefig function.
Set value for particular cell in pandas DataFrame using index
In pandas, you can set the value of a specific cell in a DataFrame using the at method.
Split string on whitespace in Python
You can use the split() method to split a string on whitespace in Python.
Static methods in Python?
In Python, a static method is a method that belongs to a class rather than an instance of the class.
Sum a list of numbers in Python
Here is a code snippet that demonstrates how to sum a list of numbers in Python:
Traverse a list in reverse order in Python
You can use the reversed() function to iterate through a list in reverse order.
Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
The truth value of a Series in pandas can be ambiguous, as it can contain multiple values.
TypeError: 'module' object is not callable
This error message typically occurs when you are trying to call a module as if it were a function.