Import SPSS Dataset in Python

Is there a way to import an SPSS dataset into Python, preferably a NumPy recarray format? I looked around, but could not find the answer.

Joon

+6
python import dataset spss
source share
7 answers

Perhaps this will help: Python reader + writer for spss sav files (Linux, Mac, and Windows) http://code.activestate.com/recipes/577811-python-reader-writer-for-spss-sav-files-linux- mac- /

+1
source share

SPSS has extensive Python integration, but is intended for use with SPSS (now known as IBM SPSS Statistics). There is an SPSS ODBC driver that can be used with Python ODBC support to read the sav file.

+3
source share

Option 1 As Rkbarni pointed out, there is a Python savReaderWriter available through pypi. I ran into two problems:

  • It relies on many additional libraries outside the seemingly clean python implementation. SPSS files are read and written in almost every case using IBM SPSS I / O modules. These modules differ in platform, and in my experience "pip install savReaderWriter" prevents them from working out of the box (on OS X).
  • The development of savReaderWriter, although not dead, is less relevant than one would hope. This complicates the first release. It uses some outdated packages to increase speed and gives some warnings at any time when you import savReaderWriter, if they are not available. This is not a problem today, but it may be a problem in the future, as IBM continues to update SPSS I / O modules to work with the new SPSS formats (they are already on version 21 or 22 if memory is used).

Option 2 I decided to use R as an average person. Using rpy2, I installed a simple function to read a file into an R-frame of data and output it again as a CSV file, which I subsequently import into python. This is a bit of rube-goldberg, but it works. Of course, this requires R, which can also be a problem to install in your environment (and has different binaries for different platforms).

+3
source share

gretl claims to import SPSS and export to various formats, as well as R statistics package . I have never dealt with SPSS data, so I can’t talk about their relative merits.

+2
source share

To be clear, the SPSS ODBC driver does not require the installation of SPSS.

+1
source share

Perhaps this will help someone:

http://sourceforge.net/search/?q=python+SPSS

Good luck

Michal

+1
source share

You could make Python an external call to spssread , a Perl script that displays the contents of the SPSS files this way you want.

+1
source share

All Articles