How-to articles, tricks, and solutions about PYTHON
How to retrieve a module's path?
You can use the __file__ attribute of a module to retrieve its path.
Writing a pandas DataFrame to CSV file
In the above code snippet, the to_csv method is used to write a DataFrame to a CSV file.
Python's equivalent of && (logical-and) in an if-statement
In Python, the logical "and" operator is represented by the and keyword.
How can I write a `try`/`except` block that catches all exceptions?
You can catch all exceptions by using the Exception class in the except block, like this:
Find which version of package is installed with pip
You can use the following command to check the version of a package installed with pip:
How to set environment variables in Python?
In Python, you can set environment variables using the os module.
How do I unload (reload) a Python module?
To unload a Python module, you can use the del statement to remove it from memory.
How to concatenate (join) items in a list to a single string
You can use the join() method to concatenate (join) items in a list to a single string in Python.
How do I remove/delete a folder that is not empty?
You can use the shutil module in Python to remove a folder that is not empty.
Converting unix timestamp string to readable date
You can use the datetime module in Python to convert a UNIX timestamp string to a readable date.
Convert list of dictionaries to a pandas DataFrame
Here is an example of how to convert a list of dictionaries to a pandas DataFrame:
How to subtract a day from a date?
You can use the datetime module in Python to subtract a day from a date.