How-to articles, tricks, and solutions about PYTHON
Convert pandas dataframe to NumPy array
In pandas, you can convert a DataFrame to a NumPy array by using the values attribute.
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.
Print string to text file
In Python, you can use the built-in open() function to create a text file and write a string to it.
Convert hex string to integer in Python
You can use the int() function in Python to convert a hex string to an integer.
Automatically create requirements.txt
You can use the pip freeze command to automatically generate a requirements.txt file in Python.
Python `if x is not None` or `if not x is None`?
The proper way to check if a variable x is not None in Python is to use if x is not None.
What do __init__ and self do in Python?
__init__ is a special method in Python classes, also known as a constructor.
Reverse / invert a dictionary mapping
Here's an example of how you can reverse or invert a dictionary mapping in Python: