如何使用Python读取/写入.xpt文件?

V-T*_*V-T 5 python sas

我是 Python 新手,正在寻找使用 Python 读取/写入 xpt 文件(SAS 数据集)的解决方案。

我从这个链接知道使用Python是可能的。但随后代码无法按预期工作。此代码中缺少的任何内容,无论是包含任何库还是安装任何库。甚至此代码中的任何语法错误。

with open('example.xpt', 'rb') as f:
for row in xport.Reader(f):
    print row
Run Code Online (Sandbox Code Playgroud)

注意:熟悉 PHP 脚本。

请帮我提供合适的解决方案。

Nar*_*mar 9

使用xport需要导入包

Import xport
Run Code Online (Sandbox Code Playgroud)

并且必须通过以下方式安装软件包

sudo pip install xport
Run Code Online (Sandbox Code Playgroud)