简体   繁体   English

如何从 python 中的 sas7bdat 文件或 xpt 文件中读取元数据?

[英]How can I read metadata from sas7bdat file or xpt file in python?

Can anybody share a code where one has to read metadata from sas7bdat or xpt file?任何人都可以分享一个必须从 sas7bdat 或 xpt 文件中读取元数据的代码吗? I have code for reading data in python with the help of the sas7bdat library but unable to figure out how to get metadata from the same file.我有在 sas7bdat 库的帮助下在 python 中读取数据的代码,但无法弄清楚如何从同一个文件中获取元数据。

I have released a package pyreadstat that wraps the C library readstat for python and gets you the metadata.我发布了一个包 pyreadstat,它为 python 包装了 C 库 readstat 并为您提供元数据。 You can also read sas7bcat files.您还可以读取 sas7bcat 文件。

You would use it like this:你会像这样使用它:

import pyreadstat

df, meta = pyreadstat.read_sas7bdat('/path/to/a/file.sas7bdat')

The meta object will have the metadata you are looking for including for instance variable labels, file encoding, file label.元对象将包含您正在寻找的元数据,包括例如变量标签、文件编码、文件标签。 There is a read_xport function for xpt files and read_sas7bcat for catalog files, which contain other pieces of metadata, for instance value labels to be used in combination with your sas7bdat file. xpt 文件有 read_xport 函数,目录文件有 read_sas7bcat 函数,其中包含其他元数据,例如与 sas7bdat 文件结合使用的值标签。

Check the complete documentation: https://github.com/Roche/pyreadstat查看完整文档: https : //github.com/Roche/pyreadstat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM