How-to articles, tricks, and solutions about PYTHON
Here is an example of how to split a string into a list of words in Python:
In Python, you can comment out a block of code by using the "#" symbol at the beginning of each line.
This error is raised when trying to encode a Unicode string using the ASCII codec, and the string contains a character that is not within the ASCII range (0-127).
Note that in above example, the DataFrame is created empty first, and then columns are added one by one using the assignment operator (=).
The Python equivalent for a case/switch statement is the if-elif-else structure.
You can use the .at or .iat methods to get the value of a specific cell in a DataFrame.
Here is a code snippet that demonstrates how to sum a list of numbers in Python:
This error message typically occurs when the command prompt or terminal is not able to find the pip executable.
You can use the "+" operator to concatenate two strings in Python.
In this code snippet, the variable "value" is being set to the integer representation of the string "invalid." However, "invalid" is not a valid integer, so the int() function will raise a ValueError.
To convert the index of a pandas DataFrame into a column, you can use the reset_index() function, and specify that you want to move the index to a new column with the inplace=True and name parameter.
You can filter a Pandas DataFrame using the isin() and ~(not in) methods.
You can raise the ValueError exception when you encounter bad or illegal argument combinations in Python.
In Python 2, dict.items() returns a list of the dictionary's key-value pairs, whereas dict.iteritems() returns an iterator over the dictionary's key-value pairs.
This error occurs when there is a mismatch in the indentation level of a block of code in Python.
collections.defaultdict is a subclass of the built-in dict class in Python.
To delete all local Docker images, you can use the following command:
You can use the itertools.permutations() function to generate all permutations of a list in Python.
The "Attempted relative import in non-package" error occurs when attempting to use a relative import within a script that is not part of a package.
To capture an exception message in Python, you can use a try-except block and the as keyword to assign the exception message to a variable.
You can use the datetime module in Python to get the current date in the YYYY-MM-DD format.
In Python, you can use the os module to change the current working directory using the chdir() function.
In Python, you can test multiple variables for equality against a single value using the == operator.
In Python, the "r" prefix before a string denotes that it is a raw string literal.
To print the full NumPy array without truncation, you can use the numpy.set_printoptions() function and set the threshold parameter to np.inf.