I have created some Python tools that make data mining easier. For example, when moving lots of data around one thing that comes up often is getting information from a spreadsheet into a Python data container such as a list. This can be done by adding some code in a Python script to open an … Continue reading Data Mining Tools: Column to Array
Python Language
Python: How to build a dictionary with two lists using zip( )
If you have two lists and would like to build a dictionary where one list will be the keys and the second list will be the values, Python has a way to do this easily using the built-inzip() function. With small enough examples, we could build our dictionary manually by typing it at the keyboard. … Continue reading Python: How to build a dictionary with two lists using zip( )
Python: How to read and write JSON
JSON is a lightweight data-interchange format that stands for JavaScript Object Notation. It so happens that JavaScript objects look exactly like Python dictionaries, so JSON objects can be thought of as portable dictionaries of key-value pairs. This portability is what makes JSON so valuable. While JSON objects can be identical to Python dictionaries, there are some … Continue reading Python: How to read and write JSON
Python: How to create GUI pop-up windows with Tkinter
When creating a program in Python, a useful thing to be able to do is to have a pop-up window appear on the screen with a special message. This can be used to give instant feedback to the user, alert the user to an error, or inform the user that the program completed successfully. In … Continue reading Python: How to create GUI pop-up windows with Tkinter
Python on the web: How to get a list of all available Python modules
If you want to get a complete list of Python modules available on your web host, you can do so with the following code: I saved the above code as a CGI script called “available_modules.py” and uploaded it to my website cgi-bin. Here is what the code produces, shown below in an iframe: For more … Continue reading Python on the web: How to get a list of all available Python modules
Python: How to print function details iteratively using inspect and getmembers
As described in a previous post, the help() function is great for seeing details about any given module function, one at at time. Python: How to use the built-in help( ) and dir( ) functions For example: print help(imageio.mimsave) However, sometimes we want to see details for all of the functions in an imported module. … Continue reading Python: How to print function details iteratively using inspect and getmembers
Python: How to generate animated .gifs
The below code can take in a list of consecutive image files and stitch them together to create an animated .gif file. It requires the imageio module. The path to the consecutive image files is set in the image_path variable. The full path to the name of the .gif file to be built is passed … Continue reading Python: How to generate animated .gifs
Python: Using requests to get web page source text
In addition to getting page lengths and status codes using the request method: Python: Using requests to get web page lengths and status codes You can also use requests to return the source code of web pages. For example: import requests sites = [ ‘http://www.python.org’, ‘http://www.jython.org’, ‘http://www.pypy.org’, ‘http://www.drudgereport.com’, ‘http://www.phys.org’, ‘http://www.bluegalaxy.info’, ‘http://www.bluegalaxy.info/codewalk’ ] for url in … Continue reading Python: Using requests to get web page source text
Python: Using requests to get web page lengths and status codes
With Python 3.6 and the requests module, it is easy to read data from the web. Here are a couple of basic things we can do with the requests module. Getting a Status code import requests r = requests.get(‘http://www.bluegalaxy.info’) print( r.status_code ) Which yields: 200 For more information about HTTP status codes, there are multiple … Continue reading Python: Using requests to get web page lengths and status codes
Python: How to use enumerate( )
Python’s built-in enumerate function takes in any iterable sequence, such as a list, and yields the elements of the sequence along with an index number. This is useful for adding a count to every element of a list. The basic syntax of this function is: enumerate(sequence, start=0) where sequence is the list or iterable data … Continue reading Python: How to use enumerate( )