- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个数据库,其中每个案例都包含有关手写数字的信息,例如:
Digit1Seq :当在 12 位数字的序列中绘制“1”时
Digit1Ht:数字“1”的高度
Digit1Width:它的宽度
Digit2Seq:数字“2”的相同信息
最多数字“12”
我发现我现在也需要以稍微不同的方式组织信息。特别是我想要一个新变量,其中写入第一个数字的高度和宽度,然后是第二个数字的高度和宽度,等等,作为 SPSS vars
第一位数字
第一个数字宽度...
第十二位宽度
这是我在 SPSS 中编写的一个 Python 程序,它应该是一个非常简单的计算,但它遇到了一种命名空间问题:
BEGIN PROGRAM PYTHON.
import spss
indices = ["1", "2", "3","4","5", "6", "7", "8", "9", "10", "11", "12"]
seq=0
for i in indices:
spss.Submit("COMPUTE seq = COMDigit" + i + "Seq.")
spss.Submit("EXECUTE.")
spss.Submit("COMPUTE COM" + indices[seq] + "thWidth = COMDigit" + i + "Width.")
spss.Submit("COMPUTE COM" + indices[seq] + "thHgt = COMDigit" + i + "Hgt.")
spss.Submit("EXECUTE.")
END PROGRAM.
seq
的值在第一
COMPUTE
命令不会返回到 Python,因此在接下来的两个中会发生正确的事情
COMPUTE
命令。 Python 的值
seq
没有改变,所以我最终得到的 SPSS 代码只给我两个变量(
COM1thWidth
和
COM1Hgt
),其中
COMDigit1Width
,
COMDigit2Width
等得到写入。
seq
每次这样字符串连接都会创建正确的
COMPUTE
?还是我只是在错误地思考这个问题?
最佳答案
将 SPSS 变量数据转换为 Python 变量进行操作的最简单方法可能是使用 spss.Dataset 类。
为此,您将需要:
1.) SPSS 数据集的数据集名称
2.) 要从中提取数据的变量的名称或其在数据集中的索引。
如果要从中提取数据的变量的名称命名为“seq”(我相信这是在您的问题中),那么您可以使用以下内容:
BEGIN PROGRAM PYTHON.
from __future__ import with_statement
import spss
with spss.DataStep()
#the lines below create references to your dataset,
#to its variable list, and to its case data
lv_dataset = spss.Dataset(name = <name of your SPSS dataset>)
lv_caseData = lv_dataset.cases
lv_variables = lv_dataset.varlist
#the line below extracts all the data from the SPSS variable named 'seq' in the dataset referenced above into a list
#to make use of an SPSS cases object, you specify in square brackets which rows and which variables to extract from, such as:
#Each row you request to be extracted will be returned as a list of values, one value for each variable you request data for
#lv_theData = lv_caseData[rowStartIndex:rowEndIndex, columnStartIndex:columnEndIndex]
#This means that if you want to get data for one variable across many rows of data, you will get a list for each row of data, but each row's list will have only one value in it, hence in the code below, we grab the first element of each list returned
lv_variableData = [itm[0] for itm in lv_caseData[0:len(lv_caseData), lv_variables['seq'].index]]
END PROGRAM.
关于python - 在 SPSS Python Essentials 中,我可以获取返回给 Python 的 SPSS 变量的值以供进一步使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17866247/
大家好我有一个应用程序可以打开一个包含文本和图像组合的文章的 WebView 。如您所知,文章有不同的字体,我想知道是否有办法让 Web View 呈现几种 Helvetica 字体,就像在安装了这些
我正在寻找一种好的格式来归档旧 Linux 计算机的整个文件系统。 西藏自治区 tar.gz 格式非常适合归档具有 UNIX 样式属性的文件,但由于压缩应用于整个归档,因此设计排除了随机访问。相反,如
我最近一直在苦苦挣扎,因为我不得不更改我不久前编写的一些代码以在 Qt 中进行图像处理和 OpenGl以支持多线程。 问题是我想用它在一组图像上应用批量过滤器, 我正在使用 openMP 来做这样的多
我已成功将两个实际设备连接到 Azure IoTHub(在同一个 IoT 中心),并希望第二个设备接收第一个设备发送的消息。因此,在普通的 MQTT 代理中,第二个设备仅订阅该主题,但 Azure没有
我需要一些 Jenkins 作业才能通过 ssh 通过 shell 命令行访问其他一些机器。 我该怎么做? 我没有目标服务器的密码,但我有一个“ key ”文件,但是当我使用以下命令运行作业时 ssh
我在 Mac OSX Mavericks 上使用 MAMP。我想安装最新的 XDebug v2.2.4。根据 XDebug 向导,我下载了 XDebug 2.2.4 源代码。我的系统上安装了许多版本的
所以我正在制作一个程序,从用户给定的 AZ Lyrics 歌曲中提取歌词。我遇到的问题是,在将字符串转换为 URL 后,它说 Jsoup 无法解析它,因为它不接受字符串,尽管变量是我们传入的 URL。
我已经安装了 AWS .NET SDK通过 MSI 安装程序。我想使用这段代码: static IAmazonS3 client; client = new AmazonS3Client(Amazon
我正在使用 cURL 检索另一个页面,除非我有特定的 cookie,否则我看不到页面内容。 cookie 名称是 seepage,它的值必须设置为 1 才能让我看到页面内容。 我想使用 cURL 加载
目录 1、VLC代码封装 1.1 QT(C++)工程 1.2static 声明 m_instance 优化效率 1.3封装 DLL
我是 Docker 新手,但有一个 Java Web 应用程序项目,我的 Maven 构建会为其生成并安装 Docker 镜像。即 mvn clean install 产品: REPOSITORY
我正在尝试在 Debian Stretch 上做一个带有 uinput 的虚拟键盘,我可以输入字符串,比如“Toto!”,键盘会写入这个字符串。但是,我一直坚持从 C char 到键盘处理的键码的转换
我们正在 Rails 中开发一个 JSON REST API,供我们也在开发的 Android 应用程序使用。有什么方法可以保护 API,使其只能由我们特定的 Android 应用程序使用? API
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
所以我有一个问题,我有 2 个应用程序部署在具有不同端口的同一网站上,一个是登录应用程序,一个是HRIS 系统。 我的问题是,当我的登录应用程序创建 token 时并重定向到我的 hris 系统,hr
在给出的第三段代码的上下文中交谈 on this page , 有一个方法 Messenger named getBinder()返回 the IBinder Messenger 用于与 associ
我目前有一个私有(private) Java 项目,我正在尝试将其完善以供其他开发人员使用。我想做的一件事是让 Ant 自己下载 JUnit、PMD 和 FindBugs 等所需的 JAR,这样开发人
我想在 Qt 中使用 ffmpeg 库进行编程。 如何在 Windows 上将 ffmpeg 编译成 *.lib 文件? 或 如何使用Qt官方发布的编译后的*.dll文件? 还有,哪种方式比较好? 最
我正在为扩展 std::vector 实例化的 C++ 类开发 Python 绑定(bind)。为了让 Python 下标运算符为此类工作,我添加了如下所示的 __getitem__ 函数(我删除了不
我正在为 Amazon SWF 的相当简单的工作流程编写 PHP。我发现自己开始编写一个库来检查某些操作是否已经开始或完成。基本上遍历事件列表以检查事情的进展情况,然后在需要时启动适当的事件。有时这可
我是一名优秀的程序员,十分优秀!