PANDAS Mac OS

Introduction

  1. If you're on a default mac install, and you've done pip install numpy -upgrade to be sure you're up to date, but pip install pandas still fails due to an old numpy, try the following: $ cd /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/ $ sudo rm -r numpy $ pip install pandas This should now install / build pandas.
  2. Pandas is an open-source Python Library providing high-performance data manipulation and analysis tool using its powerful data structures. The name Pandas is derived from the word Panel Data – an Econometrics from Multidimensional data.
  3. Python 3 Mac Os; Python 3 Download; Conda is the package manager that the Anaconda distribution is built upon. It is a package manager that is both cross-platform and language agnostic it can play a similar role to a pip and virtualenv combination. Re: Tutor Installing python and numpy on the Mac (OSX).
  4. Python Training Overview. Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. Python has been one of the premier, flexible, and powerful open-source language that is easy to learn, easy to use, and has powerful libraries for data manipulation and analysis.

Using python and pandas in the business world can be a very useful alternativeto the pain of manipulating Excel files. While this combination of technologiesis powerful, it can be challenging to convince others to use a pythonscript - especially when many may be intimidated by using the command line.In this article I will show an example of how to easily createan end-user-friendly GUI using the Gooey library. This interface is basedon 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 greatlyincrease the adoption of python in your place of business.

The Problem

Crossover

I will be basing the example in this article on my prior post - Combining Data From Multiple Excel Files.The basic concept is that there is a periodic need to combine data from multipleexcel files into a “master file” and perform some additional manipulations.

Mac Book Pro Retina, Mid 2012(OS X Yosemite 10.10.5) Raspberry Pi 3(Raspbian Jessie with PIXEL 2016-11-25) 必要なライブラリは python 、 pandas 、 matplotlib 、 seaborn になります。.

Unfortunately this process is error prone and time consuming when someone tries todo a lot of manual copying and pasting in Excel. However, it is relativelystraightforward to create python + pandas scripts to perform thesame manipulations in a more repeatable and robust format. However, as soon asyou ask the user to type something like the line below, you will lose them:

Instead, you could present them with a simple GUI that looks something like this:

The nice thing about this example is that you have standard windows directory andfile chooser dialogs along with a standard date picker widget. It will be a muchsmoother transition for your users to use this UI than to try to remember howto use the command line with all the various arguments shown above.

Panda For Mac

The rest of this article will explain how to create this UI with very minorchanges to the base code you would build using argparse. If you arenot familiar with argparse then this article might be helpful to referencebefore you go much further. As shown in the article, argparse (and friends)are very sophisticated libraries but I have found that you can create verymeaningful and useful tools with the very basic options I’ll show in this post.

Install

Gooey requires wxPython for its interface. wxPython can be a littletricky to install but if you are using the Anaconda or Miniconda distributionthe install is as simple as:

I highly recommend using conda for the install process - especially on Windows.

Gooey can then be installed using pip:

Building The Script

This notebook shows the basic idea for this program. What I will do next isbuild a simple version of this using argparse to pass in the sourceand 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 purposesof this example, I do not actually use the value. As they say, that is an exerciseleft to the reader.

The simplest example of argparse would look something like this:

When you are ready to access your arguments, you can get them like this:

One other unique aspect to this code is that I added a simple json dump of thearguments and restore them as the default next time the script is executed. Ioriginally did this to streamline the testing process but realize that this wouldbe helpful in the real world too. Here is the full code sample with the defaultvalues filled in based on the previous execution of the script.

This code allows us to do a basic command line interface that looks like this:

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

Add a Gooey GUI

The command line solution shown above is very familiar to many but I imagine thereare people in your organization that would instantly turn away from a solution thatlooks something like what I have shown above. However, Gooey makes it as easy as two lines ofcode to make a UI for this script.

The most basic steps are to import Gooey and add the decorator in front of thefunction that processes your arguments. Here is what it would look for our example:

When you run this, you would see a simple UI like this:

I think we all agree that this is fairly intuitive and would be something youcould easily explain to your most non-technical users. The other nice thing isthat 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 nicewidgets to allow them to select directories and dates. If you would like to do thatthen you can substitute the GooeyParser for your ArgParser andadd the widget information to the parser code.

Change

to

And add your widget:

Here’s what it looks like to use the DirChooser1, FileChooser andDateChooser widgets:

Now you have some native widgets the look very customary for the host OS:

The other nice feature is that when you execute the program you have a simplewrapper around the display and reasonable error windows if there is anunderlying error in your program.

One other handy component is that there is a “Restart” button at the bottom of thescreen. If you select that button, you can go back to your input screen and adjust anyvariables and re-execute the program. This is really nice if you need to run theprogram multiple times with different inputs.

Pandas Mac Os Catalina

Part of what I really like about this solution is that there is very littleadditional overhead in your code. A traditional GUI (tkinter, QT, wxWindows etc)would require a lot of code to show this UI. This example showshow unobtrusive the solution can be.

The Final Program

I have not gone into the example of the actual pandas code but you can see in thefull sample that it is relatively straightforward to use the arguments asinputs into your various python function calls. If you would like to see thecode on github, here it is.

I think you will agree that this can be a really useful solution for distributingsmall standalone programs to users that are not comfortable running python from thecommand line. I have built this example around pandas but it would work for prettymuch any python script using argparse. Obviously if you need a more robust solutionthen you’ll need to evaluate other options but I would argue that there is a lotof power in this potential solution.

Edit History

  • 9-14-2015: Corrected typos
  • 9-17-2015: Updated example code imports to include GooeyParser

Comments