Networkite新手:如何从这个python脚本中获取对象以在R中使用?

Networkite新手:如何从这个python脚本中获取对象以在R中使用?,python,r,reticulate,Python,R,Reticulate,Python脚本 #!/bin/python3 import pandas as pd import numpy as np class test(object): def checker(self): df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['a', 'b', 'c']) return df2

Python脚本

#!/bin/python3


import pandas as pd 
import numpy as np

class test(object):
    def checker(self):
        df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
                       columns=['a', 'b', 'c'])
        return df2

if __name__ == "__main__":
    q = test()
    q.checker()
我想要那个df2对象。数据帧

R码

x <- py_run_file("new1.py")

x您需要从该环境中拉出一个对象:

import pandas as pd 
import numpy as np

class test(object):
    def checker(self):
        df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
                       columns=['a', 'b', 'c'])
        return df2

if __name__ == "__main__":
    q = test()
    x = q.checker()
在R中:

库(网状)

兄弟,斯威特!聪明狼
library(reticulate)
x <- py_run_file("test.py")$x

x
  a b c
1 1 2 3
2 4 5 6
3 7 8 9