Top-rated recipes tagged "meta:requires=math" and "files"http://code.activestate.com/recipes/tags/meta:requires=math+files/top/2011-07-25T18:59:49-07:00ActiveState Code RecipesPython reader for spss sav files (Python)
2011-07-25T18:59:49-07:00Albert-Jan Roskamhttp://code.activestate.com/recipes/users/4177640/http://code.activestate.com/recipes/577650-python-reader-for-spss-sav-files/
<p style="color: grey">
Python
recipe 577650
by <a href="/recipes/users/4177640/">Albert-Jan Roskam</a>
(<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/pasw/">pasw</a>, <a href="/recipes/tags/sav/">sav</a>, <a href="/recipes/tags/spss/">spss</a>, <a href="/recipes/tags/statistics/">statistics</a>).
Revision 3.
</p>
<p><strong>Python Program to read Spss system files (.sav)</strong></p>
<ul>
<li><em>* version 2 (FASTER!) *</em></li>
<li>Requires spssio32.dll, which can be freely downloaded from:
<a href="https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%2520for%2520IBM%25C2%25AE%2520SPSS%25C2%25AE%2520Statistics?lang=en" rel="nofollow">https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%20for%20IBM%C2%AE%20SPSS%C2%AE%20Statistics?lang=en</a></li>
<li>You can also find this dll in the installation directory of SPSS (although SPSS is _not_ needed!)</li>
<li><p>The .dll should be saved in the same location as this program.</p></li>
<li><p>Parameters:
<em>savFileName</em>: the file name of the spss data file;
<em>returnHeader</em>: Boolean that indicates whether the first record
should be a list of variable names (default: True);
<em>recodeSysmisTo</em>: indicates to which value missing values should
be recoded (default: "");
<em>selectVars</em>: indicates which variables in the file should be
selected.The variables should be specified as a list or a tuple
of valid variable names. If None is specified, all variables
in the file are used (default: None);
<em>verbose</em>: Boolean that indicates whether information about the
spss data file (e.g., number of cases, variable names, file
size) should be printed on the screen (default:
True). <br />
<em>rawMode</em>: Boolean that indicates whether values should get
SPSS-style formatting,and whether date variables (if present)
should be converted to ISO-dates. If True, the program does not
format any values, which increases processing speed. (default:
= False)
<em>interfaceEncoding</em> Indicates the mode in which text communicated
to or from the I/O Module will be. Valid values are 'UTF-8' or
'CODEPAGE' (default = 'CODEPAGE')</p></li>
<li><p>Typical use:
savFileName = "d:/someFile.sav"
with SavReader(savFileName) as sav:
header = sav.next()
for line in sav:
process(line)</p></li>
<li><p>Note:
--<em>New version</em>: If you downloaded this previously, use the current version as it is <strong>MUCH faster!!</strong>
--this code currently only works on Windows (32 bits). I might make it work on Linux Ubuntu 10 at some point.
--date fields in spss are represented as the number of seconds since the Gregorian calendar. The program converts these, wherever possible, to ISO-dates (yyyy-mm-dd).</p></li>
</ul>
<p>Any feedback is welcome! I'm still learning!</p>
dal_4.py (Python)
2006-04-26T10:11:38-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/492212-dal_4py/
<p style="color: grey">
Python
recipe 492212
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>While DAL3 created and enforced a distinction
among directory blocks, file blocks, and
data blocks (along with providing an easy
interface to directory blocks and files blocks),
DAL4 introduces the concept of linking all of
these blocks together and giving names to
directories and files. While still primitive,
the file system is now unified and allows more
advanced abstractions to be built on top of it.</p>
dal_3.py (Python)
2006-04-26T10:01:43-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/492211-dal_3py/
<p style="color: grey">
Python
recipe 492211
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>Disk Abstraction Layer 3 provides a more
useful framework for secondary memory and
provides an abstract interface for
implementing a generic file system. It
renumbers the blocks on the hard drive to
start at block 1 so that block 0 can be
considered a NULL reference. At a lower
level, block 0 would be seen to be where
the OS can keep a seed for its random
number generator (interface provided).</p>
dal_2.py (Python)
2006-04-26T09:53:56-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/492210-dal_2py/
<p style="color: grey">
Python
recipe 492210
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>The class DAL2 provides a way to label
blocks on a hard drive while storing
such information on the hard drive
itself. The information is kept in the
BIT (Block Information Table) and is
written out to disk when appropriate.
Otherwise, the BIT is kept in memory
for efficiency. The hard disk is again
presented as a collection of blocks but
completely hides disk IO as a result of
Disk Abstraction Layer 1.</p>