How-to articles, tricks, and solutions about PYTHON
Unzipping files in Python
Here is a code snippet that demonstrates how to unzip a file using the zipfile module in Python:
What can I do about "ImportError: Cannot import name X" or "AttributeError: ... (most likely due to a circular import)"?
This error typically occurs when there is a circular import between two or more modules.
When to use cla(), clf() or close() for clearing a plot in matplotlib?
cla() is used to clear the current axis of a plot in matplotlib.
How do I use raw_input in Python 3?
In Python 3, the input() function can be used in place of raw_input() to read input from the user.
if else in a list comprehension
Here's an example of using an if-else statement within a list comprehension:
List attributes of an object
In Python, you can use the built-in function dir() to list the attributes of an object.
Working with UTF-8 encoding in Python source
Here is a code snippet that demonstrates how to work with UTF-8 encoding in a Python source file:
Extracting just Month and Year separately from Pandas Datetime column
You can extract the month and year separately from a Pandas datetime column using the dt accessor.
In Python, how do I convert all of the items in a list to floats?
You can use a for loop and the float() function to convert each item in a list to a float.
Convert columns to string in Pandas
To convert all columns in a Pandas DataFrame to strings, you can use the following code snippet:
I'm getting Key error in python
A KeyError in Python is raised when a dictionary key is not found in the dictionary.
Check if a word is in a string in Python
You can use the in keyword to check if a word is in a string in Python.
Python int to binary string?
You can use the built-in bin() function to convert an integer to a binary string in Python.
Dump a NumPy array into a csv file
Here's an example code snippet that demonstrates how to dump a NumPy array into a CSV file: