Introduction To Python Programming And Developing Gui Applications With Pyqt Pd

Introduction To Python Programming And Developing Gui Applications With Pyqt Pd Rating: 10,0/10 4506 votes

An interactive environment for python built around a matlab style console window and editor. It was designed to provide a python based environment similiar to Matlab for scientists and engineers however it can also be used as a general purpose interactive python environment especially for interactive GUI programming.

Introduction Using python and pandas in the business world can be a very useful alternative to the pain of manipulating Excel files. While this combination of technologies is powerful, it can be challenging to convince others to use a python script - especially when many may be intimidated by using the command line. In this article I will show an example of how to easily create an end-user-friendly GUI using the library. This interface is based on wxWindows so it looks like a “native” application on Windows, Mac and Linux. Ultimately, I believe that presenting a simple user interface to your scripts can greatly increase the adoption of python in your place of business. The Problem I will be basing the example in this article on my prior post -. The basic concept is that there is a periodic need to combine data from multiple excel files into a “master file” and perform some additional manipulations.

Unfortunately this process is error prone and time consuming when someone tries to do a lot of manual copying and pasting in Excel. However, it is relatively straightforward to create python + pandas scripts to perform the same manipulations in a more repeatable and robust format. However, as soon as you ask the user to type something like the line below, you will lose them. The nice thing about this example is that you have standard windows directory and file chooser dialogs along with a standard date picker widget.

It will be a much smoother transition for your users to use this UI than to try to remember how to use the command line with all the various arguments shown above. The rest of this article will explain how to create this UI with very minor changes to the base code you would build using argparse. If you are not familiar with argparse then might be helpful to reference before you go much further. As shown in the article, argparse (and friends) are very sophisticated libraries but I have found that you can create very meaningful and useful tools with the very basic options I’ll show in this post.

Building The Script This shows the basic idea for this program. What I will do next is build a simple version of this using argparse to pass in the source and destination directories as well as a location for the customer-status.xlsx file. I am going to create a parse_args function to set up the following required inputs: • data_directory • output_directory • Customer account status file I will add an example of an optional date argument as well but for the purposes of this example, I do not actually use the value. As they say, that is an exercise left to the reader. The simplest example of argparse would look something like this.

From argparse import ArgumentParser parser = ArgumentParser ( description = 'Create Quarterly Marketing Report' ) parser. Add_argument ( 'data_directory', action = 'store', help = 'Source directory that contains Excel files' ) parser. Klipart denj nezavisimosti rossii. Add_argument ( 'output_directory', action = 'store', help = 'Output directory to save summary report' ) parser.

Add_argument ( 'cust_file', action = 'store', help = 'Customer Account Status File' ) parser. Add_argument ( '-d', help = 'Start date to include' ) args = parser. Parse_args () When you are ready to access your arguments, you can get them like this. Python pandas_gui_args.py --help usage: pandas_gui_args.py [-h ] [-d D ] data_directory output_directory cust_file Create Quarterly Marketing Report positional arguments: data_directory Source directory that contains Excel files output_directory Output directory to save summary report cust_file Customer Account Status File optional arguments: -h, --help show this help message and exit -d D Start date to include The main section of the code would look like the section below. The basic flow is: • Get the command line inputs • Pass the appropriate ones to the input and processing functions • Save the data to the desired location.

I think we all agree that this is fairly intuitive and would be something you could easily explain to your most non-technical users. The other nice thing is that it runs the same on Windows, Mac or Linux (as illustrated above). The one challenge would be that users would probably expect to have some nice widgets to allow them to select directories and dates. If you would like to do that then you can substitute the GooeyParser for your ArgParser and add the widget information to the parser code. One other handy component is that there is a “Restart” button at the bottom of the screen. If you select that button, you can go back to your input screen and adjust any variables and re-execute the program. This is really nice if you need to run the program multiple times with different inputs.