Basics of setting up a Spyder workspace and projects

I use spyder for data analysis and I have just started using the project workspace. I believe that it allows you to write better code due to the organization. As a previous post stated that "This can be helpful in web development", which is true because web development requires good software engineering due to the complexity of the files and how they interact with each other. This organization/structure can be used in data analysis as well.

Often, data analysts that use Anaconda have an engineering or science background, not necessarily software engineering or computer science. This means that good software engineering principles may be missing (myself included). Setting up a workspace does one critical thing that I believe is missing from the discussion. It adds the workspace to the system path. Set up a project and then try

import sys
print sys.path

You will see your project's directory added to the PYTHONPATH . This means I can break up my project and import functions from different files within my project. This is highly beneficial when analysis becomes complex or you want to create some type of larger model that will be used on a regular basis. I can create all of my functions in one file, maybe functions for plots in another and then import them in a separate script file.

in myScript.py

from myFunctions import func1
from myFunctions import func2
from myPlots import histPlot

This is a much cleaner approach to data analysis and allows you to focus on one specific task at a time.

In python 3 there is the %autoreload capability so you can work on your functions and then go back to your script file and it will reload them each time if you find errors. I haven't tried this yet bc the majority of my work is in 2.7, but this would seem to add even greater flexibility when developing.

So when should you do this? I think it is always a good idea, I just started using this setup and I will never go back!


Update Oct 2016: Spyder 3 now has project facilities similar to that of other IDEs (especially Rstudio).

Now you if you have a folder with scripts, you can go to

Projects > New Projects > Existing Directory

to import it. The selected directory will be set as the base directory for the project.

Tags:

Python

Spyder