是否有用于打开 SPSS 文件的 Python 模块? [英] Is there a Python module to open SPSS files?

查看:25
本文介绍了是否有用于打开 SPSS 文件的 Python 模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有 Python 模块可以打开 IBM SPSS(即 .sav)文件?如果有不需要任何额外 dll 文件/库的最新内容,那就太好了.

Is there a module for Python to open IBM SPSS (i.e. .sav) files? It would be great if there's something up-to-date which doesn't require any additional dll files/libraries.

推荐答案

我发布了一个 Python 包pyreadstat",它可以读取 SPSS(sav、zsav 和 por)、Stata 和 SAS 文件.它是 C 库 ReadStat 的包装器,因此速度非常快.readstat是R库Haven后面用到的库,应用广泛,非常健壮.

I have released a python package "pyreadstat" that reads SPSS (sav, zsav and por), Stata and SAS files. It is a wrapper around the C library ReadStat so it is very fast. Readstat is the library used in the back of the R library Haven, which is widely used and very robust.

该包是自动包含的.它不需要使用 R(不需要安装额外的应用程序)并且它不依赖于 IBM dll 或其他外部库.

The package is autocontained. It does not require using R (no need to install an aditional application) and it does not depend on IBM dlls or other external libraries.

例如,为了读取 SPSS sav 文件,您可以执行以下操作:

For example, in order to read a SPSS sav file you would do:

import pyreadstat

df, meta = pyreadstat.read_sav("/path/to/sav/file.sav")

df 是一个熊猫数据框.Meta 包含元数据,例如变量标签或值标签.read_sav 读取 sav 和 zsav(压缩)文件.还有一个函数 read_por 用于旧的 por(便携式)文件.

df is a pandas dataframe. Meta contains metadata such as variable labels or value labels. read_sav reads both sav and zsav (compressed) files. There is also a function read_por for old por (portable) files.

您可以在这里找到它:https://github.com/Roche/pyreadstat

这篇关于是否有用于打开 SPSS 文件的 Python 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆