Six ways to reverse pandas dataframe

In this post we will learn how to reverse pandas dataframe. We start by changing the first column with the last column and continue with reversing the order completely. After we have learned how to do that we continue by reversing the order of the rows. That is, pandas data frame can be reversed such that the last column becomes the first or such that the last row becomes the first.

Continue reading

Why Spyder is the Best Python IDE for Science

Spyder is the best IDE that I have tested so far for doing data analysis, but also for plain programming. In this post I will start to briefly describe the IDE. Following the description of this top IDE the text will continue with a discussion of my favourite features. You will also find out how to install Spyder on Ubuntu 14.04 and at the end of the post you will find a comparison of Rodeo (a newer IDE more RStudio like) and Spyder.

When I started programming in Python I used IDLE which is the IDE that you will get with your installation of Python (e.g., on Windows computers). I actually used IDLE IDE for some time. It was not until I started to learn R and found  RStudio IDE. I thought that RStudio was great (and it still is!). However, after learning R and RStudio I started to look for a better Python IDE. Continue reading

Every Psychologist Should Learn Programming

The aim of this post is to show you why you, as a psychology student or researcher (or any other kind researcher or student) should learn to program. The post is structured as follows. First I start with discussing why you should learn programming and then give some examples when programming skills are useful. I continue to suggest two programming languages that I think all Psychology students and researchers should learn.

Continue reading

R resources for Psychologists

Good resources for learning R as a Psychologist are hard to find. By that I mean that there are so many great sites and blogs around the internet to learn R. Thus, it may be hard to find learning resources that targets Psychology researchers. Recently I wrote about 4 good R books targeted for Psychology students and researchers (i.e., R books for Psychologists). There are, however, of course other good resources for Psychological researchers to learn R programming. Therefore, this post will list some of the best blogs and sites to learn R.  The post will be divided into two categories; general and Psychology focused R sites and blogs. For those who are not familiar with R I will start with a brief introduction on what R is (if you know R already;click here to skip to the links).

What is R?

R is a free and open source programming language and environment. Data analysis in R is carried out by writing scripts and functions. R is a complete, interactive, object-oriented language.

R for Psychologists. R is interactive.
R is interactive

In R statistical environment you are able to carry out a variety of statistical and graphical techniques. For instance, linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, and many more can be carried using both frequentist and bayesian paradigms.

You may want to start with R commander. It provides a menu which may make learning R a bit easier at the beginning. R can be downloaded here: The Comprehensive R Archive Network.


R resources

R has a broad and helpful community and, therefore, there are many good resources for learning the language. Continue reading

Rodeo - RStudio for Python - a good IDE for doing Data Science

Installing Rodeo IDE on Linux

I recently wrote a post on the RStudio like Python IDE Rodeo (RStudio-like Python IDEs – Rodeo and Spyder). In that post, I installed and tested Rodeo 0.44. However, Rodeo 1.0 was released in October. Rodeo 1.0 cannot be installed using Pip. Therefore, I wrote a bash script for downloading and unzipping Rodeo. Note, the script below will now install Rodeo 2 and is tested on my Ubuntu 16.04 machines.

What is Rodeo?

Rodeo is, as previously mentioned, a Python IDE very similar to RStudio. It is intended to use for Data Science. If you are coming from R and plan to add Python to your stack, Rodeo is probably going to be very familiar to you. Given that you have used RStudio, that is. I would still say that Spyder may be a better IDE for doing Data Science in Python. Why? Because, up to date, there are plenty of more features in Spyder compared Rodeo. Update: now you will get a .deb file when using wget (see below). Thus, we can use dpkg to install the Rodeo.

Installing Rodeo

The above code will download the Linux 64 binaries for Rodeo, unzip it into the ‘/usr/local/bin’ directory, and remove the downloaded file. Finally, a symbolic link to the executable is created. Obviously, you can change 64 to 32 to download and install Rodeo 32 bit. Note, you can just cut & paste the code and paste it into a command window. If you, however, save it as a bash script (i.e., you need to make it executable; chmod +x To download and install Rodeo:

I have tested installing Rodeo IDE on Ubuntu 14.04 and 16.04 with the above script. If you don’t have Jupyter and Matplotlib installed it may need to install them also;

Thats all, now you should know how to easily download and install Rodeo 1.0 on your Linux machine. Please let me know if you need to do more than I described in this post,

Arduino plus a vibrating coin motor

Recently we bought 10 coin like vibrating motors from Precision Microdrives. In the following video you will one of them in use. It is connected to an Arduino Uno micro controller.

Now we have built some wrist bands/straps using the vibrating motors, velcro, silver tape, arduino, batteries and more.

Hopefully, we will have a couple of interesting research projects that make use of them in a near future (currently we have two planned). Right now the plan is to use PsychoPy to control them for our experiments. In fact, we have one planned to start in two weeks and another for being piloted this week. One more applied cognitive psychology/human factors and the other project more ground research. Very exiting. I may update the blog with a new post when we tested more.

What language should I learn next year?

What programming language should I learn – 2

I recently asked which programming language I should learn next year (i.e., 2016). In this post I will evaluate the alternatives that I have by asking the question in different places around the internet. The post will end with the choice I made and how to install the language

To summarize my earlier post, I mainly use programming for creating Psychology experiments and, thus,  need a powerful language. Furthermore, in Psychological experiments stimuli are typically being presented (e.g., sounds, images, text, or video). Responses need to be collected from the keyboard, mouse and specially built equipment (e.g., via USB; Arduino). For some experiments timing of the presentation and collection of responses might be significant.  The language should, of course, be free, open source, and work on a computer running Windows, Linux, and OS-X. However, mobile platforms such as Smartphones and Tablets might also be interesting in the future. Note that all languages considered are more or less general purpose languages and might, therefore, be attractive to anyone that want to extend their stack and learn a new programming language 2016.

One of the most valuable answers I got was that I should look for a functional language.

Continue reading

TrialHandler – a PsychoPy tutorial

In this tutorial you will get to know how to use the PsychoPy function TrialHandler to create trials and correct responses to your targets in these trials. PsychoPy is an application for creating experiments for Psychology experiments. The application is written in Python, an easy programming language to learn. You can learn more about PsychoPy in my two previous posts (Free and Useful software – PsychoPy and Python apps and libraries…”).
Continue reading

R from Python – an rpy2 tutorial

rpy2 tutorial

Recently I found the Python module rpy2. This module offers a Python interface to R. Obviously; rpy2 requires that you have both R (version 3.2+) and Python (versions 2.7 and 3.3) installed.  There are pre-compiled binaries available for Linux and Windows (unsupported and unofficial, however). In this short tutorial, I will show you how to do carry out a repeated measures ANOVA (rmANOVA) using the r-packages ‘afex‘ and ‘lsmeans‘, Python, and rpy2.

Continue reading