Ultimately, I am attempting to plug a variable label into GGRAPH. I.e., how to plug a variable label into a command like. GUIDE: axis(dim(2), label(" "), delta(1), start(-3)) ^^^^ to approach this I am now doing a minimal Python program that just prints the variable name and label. I found varIndex in the manual but that did not work. Traceback (most recent call last):What should I put in the line in red below? data list list/ year(f4) zscore1 to zscore4 (4f6). begin data 1993 -.25 -2.08 1.00 -1.33 end data. variable labels Zscore1 'some set of words' Zscore2 'A second set of words' Zscore3 'third set of words' Zscore4 'words and words'. *this works. begin program. variables='Zscore1 to Zscore4' import spss,spssaux vardict = spssaux.VariableDict() vList=spssaux.VariableDict().expand(variables) for vnam in vList: print vnam end program. *this does not. begin program. variables='Zscore1 to Zscore4' import spss,spssaux vardict = spssaux.VariableDict() vList=spssaux.VariableDict().expand(variables) for vnam in vList: vlab = vardict[vnam].VariableLabel print vnam, vlab end program. -- Art Kendall Social Research Consultants
Art Kendall
Social Research Consultants |
This small tweak works.
begin program. variables='zscore1 to zscore4' import spss,spssaux vardict = spssaux.VariableDict() vList=spssaux.VariableDict().expand(variables) for vnam in vList: print vnam vlab = vardict[vnam].VariableLabel print vnam, vlab end program. Remember that the VariableDict object is case sensitive, although the docstring for expand says (correctly) case is IGNORED here, unlike elsewhere in this class. Alternatively you can use a caseless dictionary, which has a little more overhead vardict = spssaux.VariableDict(caseless=True) The caseless option was added in 2009. With an old version of Statistics you might need to download spssaux.py from the SPSS Community site. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Art Kendall <[hidden email]> To: [hidden email], Date: 06/11/2013 03:55 PM Subject: [SPSSX-L] Python index problem How to subscript into dictionary? Sent by: "SPSSX(r) Discussion" <[hidden email]> Ultimately, I am attempting to plug a variable label into GGRAPH. I.e., how to plug a variable label into a command like. GUIDE: axis(dim(2), label(" "), delta(1), start(-3)) ^^^^ to approach this I am now doing a minimal Python program that just prints the variable name and label. I found varIndex in the manual but that did not work. Traceback (most recent call last): File "<string>", line 7, in <module> File "C:\PROGRA~1\IBM\SPSS\STATIS~1\22\Python\Lib\site-packages\spssaux\spssaux.py", line 1094, in __getitem__ raise ValueError, _msg10 ValueError: Variable not in this dictionary What should I put in the line in red below? data list list/ year(f4) zscore1 to zscore4 (4f6). begin data 1993 -.25 -2.08 1.00 -1.33 end data. variable labels Zscore1 'some set of words' Zscore2 'A second set of words' Zscore3 'third set of words' Zscore4 'words and words'. *this works. begin program. variables='Zscore1 to Zscore4' import spss,spssaux vardict = spssaux.VariableDict() vList=spssaux.VariableDict().expand(variables) for vnam in vList: print vnam end program. *this does not. begin program. variables='Zscore1 to Zscore4' import spss,spssaux vardict = spssaux.VariableDict() vList=spssaux.VariableDict().expand(variables) for vnam in vList: vlab = vardict[vnam].VariableLabel print vnam, vlab end program. -- Art Kendall Social Research Consultants Art Kendall View this message in context: Python index problem How to subscript into dictionary? Sent from the SPSSX Discussion mailing list archive at Nabble.com. |
I have looked at this a
dozen times.
The only tweak I can spot is the line "print vnam" has been added. What am I missing? I am using v22. begin program. variables='zscore1 to zscore4' import spss,spssaux vardict = spssaux.VariableDict() vList=spssaux.VariableDict().expand(variables) for vnam in vList: print vnam vlab = vardict[vnam].VariableLabel print vnam, vlab end program. Art Kendall Social Research ConsultantsOn 6/11/2013 10:27 PM, Jon K Peck [via SPSSX Discussion] wrote: This small tweak works.
Art Kendall
Social Research Consultants |
Hi I'll be out of the office today until Friday (14) PM. I will check mail intermittently and get back to you as soon as i can Thanks John |
In reply to this post by Jon K Peck
WOW!
It also works if I replace "print vnam" with "junk= vnam" !!??!! Art Kendall Social Research ConsultantsOn 6/11/2013 10:27 PM, Jon K Peck [via SPSSX Discussion] wrote: begin program.
Art Kendall
Social Research Consultants |
Being a Newbie with Python I find it unpredictable to find the variable spelling with initial capital in the 'variables= ...' declaration being forwarded to the output instead of returning the actual spelling in the dictionary.
(Added 'caseless=True' to test different spelling) /PR * data list list/ year(f4) zscore1 to zscore4 (4f6). * begin data...end data. begin program. variables='Zscore1 to Zscore4' import spss,spssaux vardict = spssaux.VariableDict(caseless=True) vList=spssaux.VariableDict().expand(variables) print 'vList =', vList for vnam in vList: vlab = vardict[vnam].VariableLabel print vnam, vlab end program. Output (note variable spelling): vList = ['Zscore1', u'zscore2', u'zscore3', 'Zscore4'] Zscore1 some set of words zscore2 a second set of words zscore3 third set of words Zscore4 words and words |
I will be out of office on Thursday, June 13th, with limited access to email. I will respond to your email when I return. |
In reply to this post by PRogman
Thanks for your email, I am out of office on June 13 and will be back on June 14. I will respond to your email as soon as I get a chance. For
urgent matters, please contact Kelly Freitas at 916-858-5381. MailGate made the following annotations |
In reply to this post by PRogman
The expand method is the only VariableDict
method that ignores case unless you are using a caseless dictionary. If
you are using expand in the context of generating syntax for a Submit call,
case won't matter, but for VariableDict purposes it does. Since Python
itself is case sensitive in everything and Statistics is not, there's a
bit of a culture clash here as well as some extra overhead for caseless
dictionaries. That overhead won't be detectable unless the dictionary
is very large.
Perhaps I should have implemented expand as case sensitive, but at the time that seemed to make things less helpful. I suppose an api that returned the correctly cased name for an input argument would be useful, but if this matters, you might as well use a caseless dictionary. Regards, Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: PRogman <[hidden email]> To: [hidden email], Date: 06/13/2013 07:47 AM Subject: Re: [SPSSX-L] Python index problem How to subscript into dictionary? Sent by: "SPSSX(r) Discussion" <[hidden email]> Being a Newbie with Python I find it unpredictable to find the variable spelling with initial capital in the 'variables= ...' declaration being forwarded to the output instead of returning the actual spelling in the dictionary. (Added 'caseless=True' to test different spelling) /PR * data list list/ year(f4) *z*score1 to *z*score4 (4f6). * begin data...end data. begin program. variables='*Z*score1 to *Z*score4' import spss,spssaux vardict = spssaux.VariableDict(*caseless=True*) vList=spssaux.VariableDict().expand(variables) print 'vList =', vList for vnam in vList: vlab = vardict[vnam].VariableLabel print vnam, vlab end program. /Output (note variable spelling):/ vList = ['Zscore1', u'zscore2', u'zscore3', 'Zscore4'] *Z*score1 some set of words *z*score2 a second set of words *z*score3 third set of words *Z*score4 words and words -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Python-index-problem-How-to-subscript-into-dictionary-tp5720680p5720696.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |