Loading a .rds file in Pandas

If you would prefer not having to install R (rpy2 requires it), there is a new package “pyreadr” to read Rds and RData files very easily.

It is a wrapper around the C library librdata, so it is very fast.

You can install it easily with pip:

pip install pyreadr

Then you can read your rds file:

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 

The repo is here: https://github.com/ofajardo/pyreadr

Disclaimer: I am the developer of this package.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)