我下载了一个 .rds 格式的文件,如何使用 Pandas 加载它?它应该是一个 R 文件,但我找不到任何有关如何加载它的信息。
最佳答案
如果您不想安装 R(rpy2 需要它),有一个新包“pyreadr”可以非常轻松地读取 Rds 和 RData 文件。
它是 C 库 librdata 的包装器,因此速度非常快。
您可以使用 pip 轻松安装:
pip install pyreadr
然后你就可以读取你的rds文件了:
import pyreadr
result = pyreadr.read_r('/path/to/file.Rds') # also works for RData
# done!
# result is a dictionary where keys are the name of objects and the values python
# objects. In the case of Rds there is only one object with None as key
df = result[None] # extract the pandas data frame
repo 在这里:https://github.com/ofajardo/pyreadr
免责声明:我是这个包的开发者。
关于python - 在 Pandas 中加载 .rds 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40996175/