前面几期讲过spss语法处理缺失值,这期让spss调用Python进行检索缺失值。
DATA LIST LIST (',') /numVar (f) stringVar (a4).
BEGIN DATA
0,a
1,b
,c
3,,
4,,
END DATA.
MISSING VALUES stringVar (' ') numVar(0).
BEGIN PROGRAM.
import spssdata
data=spssdata.Spssdata(convertUserMissing=False)
# Compile and store missing value information for the variables
# in the current cursor.
data.makemvchecker()
# Loop through the cases in the active dataset.
for i,row in enumerate(data):
# Check if the current case (row) has missing values.
if data.hasmissing(row):
print "引索: " + str(i+1)
# Loop through the variables in the current cursor.
for name in data.varnames():
varvalue = row[data.getvarindex(name)]
if varvalue==None:
print "\tThe value for variable " + str(name) + \
" is system-missing."
elif data.ismissing(name,varvalue):
print "\tThe value for variable " + str(name) + \
" is user-missing."
data.CClose()
END PROGRAM.
这时我们就可以在output栏里看到哪些被试具有缺失值,一个是系统缺失,另一个是人为设置缺失值,最后我们可以对缺失值进行处理。
领取专属 10元无门槛券
私享最新 技术干货