| Date: | Mon, 19 Dec 2005 21:45:22 -0600 |
| Reply-To: | "Peck, Jon" <peck@spss.com> |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | "Peck, Jon" <peck@spss.com> |
| Subject: | Re: Getting at the value labels w/ Python |
|
| Content-Type: | text/plain; charset="utf-8" |
There are a few ways to do this. Here is a code fragment:
vard = spssaux.VariableDict() #construct a dictionary
for a particular variable, you can say something like
xvallabels=vard['x'].ValueLabels
or
xvallabels=vard.ValueLabels('x')
The return value, which is the same in either case, is a Python dictionary, so, to get the label of the value 1, for example, you could say
print xvallabels[1]
Hope that helps. There is an example file in the spssaux topic that should illustrate this and is heavily commented.
Regards,
Jon Peck
SPSS (and author of the spssaux module)
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Matt Eberle
Sent: Monday, December 19, 2005 4:36 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: [SPSSX-L] Getting at the value labels w/ Python
Hi, everyone.
I'm working on setting up a Python script to build a variable based on two
(or more) parents. I need to get access to the value labels for the
parents to correctly label the children.
The examples code included with the Python add-in for SPSS 14.x references
a class called VariableDict():
* The VariableDict class allows you to easily access dictionary
information, like variable labels, value labels, and missing values.
I've tried everything I can find in the manual to get the value labels out
and nothing works. I can see that the labels themselves are included by
the "Select where the labels are missing" code included in the examples so
they must be there..
Any help would be greatly appreciated. Thanks!
~Matt
|