PANDAS Mac OS

Posted on  by

1:07 can just click on the proper operating system and get your download options. 1:12 So, for the Mac OS X computers, we have two options here. 1:16 We have Python 3.5 and Python 2.7 right below. 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 になります。. Panda Antivirus for Mac offers Mac users complete protection against viruses and other Internet threats. Mac users have always believed they were safe from malware attacks. Yet this is definitely. Pandas is an data analysis module for the Python programming language. It is open-source and BSD-licensed. Pandas is used in a wide range of fields including academia, finance, economics, statistics, analytics, etc.

Introduction

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

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.

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.

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:

Pandas Ma Crossover

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:

Pandas Mosaic Plot

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.

PANDAS Mac OS

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.

Mac Os Download

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.

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

Pandas is an data analysis module for the Python programming language. It is open-source and BSD-licensed.

Pandas is used in a wide range of fields including academia, finance, economics, statistics, analytics, etc.

Related course:Data Analysis with Python Pandas

Install Pandas

The Pandas module isn’t bundled with Python, so you can manually install the module with pip.

Linux

If you use Linux, you can use one of the commands below to install pandas.

For Ubuntu Users

For Fedora Users

Windows

For Windows uses, you can do the following:

pip is likely in:

Apple Mac OS X

To install pandas on Mac OS X, first install python.
If Python is not installed,

Then install pandas with pip.

Related course:Data Analysis with Python Pandas