Page 1 of 1

Wie kann ich Etiketten bewahren, wenn die SPSS -Datei (.sav) über RPY in Pandas importiert wird?

Posted: 10 Apr 2025, 05:48
by Anonymous
Ich möchte mit Pandas an einer SPSS -Dateien (.sav) arbeiten. In the absence of the SPSS program, here's what a typical file looks like when converted to .csv:

Image


On investigation into what the first two rows signify (I don't know SPSS), es scheint, dass die erste Zeile das Etikett s enthält, während die zweite Zeile den Varname s. Pandas also: < /p>

Code: Select all

import pandas.rpy.common as com

def savtocsv(filename):
w = com.robj.r('foreign::read.spss("%s", to.data.frame=TRUE)' % filename)
w = com.convert_robj(w)
return w
and then do a head(), the first row (Label) is missing:

Image


How can labels be beibehalten?>