Vaibhav
Vaibhav

Reputation: 338

Is there a way to return a dataframe from Python to R ?

I'm using the system() function to trigger a Python script from R, The python script writes a data frame into a .csv file which then needs to be imported to R. I was wondering if I could directly return the data frame from Python to R.

R

command = "python"
path2script='"/Desktop/testing_connection.py"'
allArgs = path2script
output = system2(command, args = allArgs, stdout=TRUE)

Python

df_temp = pd.read_csv('/Desktop/items.csv')
print(df)

I want to return a dataframe from Python to R Currently 'output' is being created as a character vector.

Upvotes: 3

Views: 714

Answers (2)

hvollmeier
hvollmeier

Reputation: 2986

Install rpy. rpy is a simple, easy-to-use interface to R from Python. It enables one to enjoy the elegance of Python programming while having access to the rich graphical and statistical capabilities of R. The feather format as suggested by a commentator may also be of help if file I/O is mostly what you want it for.

Upvotes: 1

YCR
YCR

Reputation: 4012

The Feather format may accelerate your code.

I am not aware of a way to have one dataframe in r that you can access in python. The reason I doubt it is possible is that it is two different software, so the interoperability of data is really difficult to implement(if possible).

Upvotes: 1

Related Questions