How-to articles, tricks, and solutions about PYTHON
In Python, you can use the self keyword to refer to the instance of the enclosing class within a method.
To unload a Python module, you can use the del statement to remove it from memory.
To update pip itself from inside your virtual environment, you can use the following command:
To upgrade the Python installation in Windows 10, you can use the pip package manager.
You can use the numpy library's arange() function to specify a decimal step value for the range.
In Python 3, the input() function can be used in place of raw_input() to read input from the user.
Here is an example of how you might wait for a key press in Python:
To write JSON data to a file in Python, you can use the json module.
In Python, you can extract a column from a multi-dimensional array (e.g.
You can use the ^ operator to get the logical XOR of two variables in Python.
In Python, you can use the ceil() function from the math module to round a number up.
You can use the pytest.raises function to test that a Python function throws an exception.
collections.defaultdict is a subclass of the built-in dict class in Python.
In Python, super() is used to call a method from a parent class.
In Python, the @property decorator is used to define a method as a "getter" for a class property.
To activate a virtual environment in Linux, you can use the source command and the path to the activate script that is located in the virtual environment's bin directory.
You can add a new column to an existing pandas DataFrame by using the assign() method or the [] notation.
In pandas, you can add an empty column to a DataFrame using the assign() method or the insert() method.
In Windows, you can add to the PYTHONPATH environment variable to make sure that Python can find your modules and packages.
To apply a function to two columns of a Pandas DataFrame, you can use the apply() method of the DataFrame and pass the function as an argument.
To calculate the number of days between two dates, you can use the timedelta class from the datetime module.
You can use the traceback module to catch and print the full exception traceback without halting/exiting the program.
In Python, you can use the built-in upper() method to change a string to uppercase.
You can change the figure size of a Seaborn plot by using the set_size_inches() method of the matplotlib.pyplot.figure object and passing in the desired width and height.
There are a couple of ways to change the font size on a matplotlib plot.