Python Leftovers
posted by Roy Schestowitz on May 25, 2023
-
To remove special characters from a string the “regular expressions”, “looping”, “join(), and filter()” methods, and the “replace()” method are used in Python.
-
The “compile()” function in Python is a built-in function that is utilized to compile Python code into “bytecode” by accepting several parameters.
-
To create a pie chart in Python, the “matplotlib” library’s “pie()” function can be used along with the multiple required parameters.
-
To copy a file various methods are used in Python such as “shutil.copyfile”, “shutil.copy()”, “read()” with “write()” and “shutil.copyfileobj()”.
-
The “numpy.linalg.inv()” function of the “numpy.linalg” module is utilized to compute the inverse of the given nonsingular matrix.
-
The Python “next()” function iterates over an iterable object and returns the next item from the iterable and stops with the exception when no items are left.
-
The “sorted()” function is used to sort the strings, lists, tuples, etc. in ascending or descending order or based on single or multiple “key” parameter values.
-
To remove all instances from the input string in Python, the “remove()”, “filter()”, and “list comprehension” methods are used.
-
The “built-in file” operations, “regular expressions'', “read()” and “readlines()” methods are used to find a string in a file and print it in Python.
-
Python has several methods for overwriting files such as the “write()” method, the “truncate()” method, the mode “w”, “shutil” module, or the “os” module, etc.
-
To compare strings in Python, various methods such as the “Comparison Operators” or the “is” and “is not” operators are used.
-
To create single or multiple vertical lines and spans on your plots various methods such as “axvline()”, “vlines()”, and “ax.axvspan()” are used in Python.
-
The Pandas “to_records()” method converts a DataFrame to a NumPy record array, which can be exported to other applications.
-
To list files in a directory in Python, apply the “os.listdir()”, “glob.glob()”, “os.walk()”, “scandir()” functions or the “pathlib.Path.glob()” method.
-
Python “dictionaries” are a flexible data structure used in a broad range of applications and can be created via “curly braces {}” or “dict()” function.