Wie kann ich Etiketten bewahren, wenn die SPSS -Datei (.sav) über RPY in Pandas importiert wird?
Posted: 10 Apr 2025, 05:48
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:

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>
and then do a head(), the first row (Label) is missing:

How can labels be beibehalten?>

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

How can labels be beibehalten?>