-
-
Save radovankavicky/dcedc19648e2fa1fc4368430f51adc33 to your computer and use it in GitHub Desktop.
Python and .RData files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import rpy2.robjects as robjects | |
| import pandas.rpy.common as com | |
| import pandas as pd | |
| ## load .RData and converts to pd.DataFrame | |
| robj = robjects.r.load('test.RData') | |
| # iterate over datasets the file | |
| for sets in robj: | |
| myRData = com.load_data(sets) | |
| # convert to DataFrame | |
| if not isinstance(myRData, pd.DataFrame): | |
| myRData = pd.DataFrame(myRData) | |
| ## save pd.DataFrame to R dataframe | |
| df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]}, | |
| index=["one", "two", "three"]) | |
| r_dataframe = com.convert_to_r_dataframe(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment