我正在尝试将PyCall.jlwrap('Julia')对象转换为数据帧。我使用PyJulia在Julia中运行一个优化算法,结果是抛出一个dataframe对象。我想将该对象转换为数据帧
这是一个类似于5年前提出的问题。但是,没有任何代码建议如何完成传输
任何帮助都是有用的
这是我目前设置的代码。知道“优化程序”后台发生的事情并没有多大用处,只知道“run\u hybrid”和“run\u storage”命令返回的是一个数据帧:
### load in necessary modules for pyjulia
from julia import Main as jl
##load my user defined module
jl.include("optimization_program_v3.jl")
##run function from module
results = jl.run_hybrid(generic_inputs)
##test type of item returned
jl.typeof(results)
returns: <PyCall.jlwrap DataFrame>
##try to convert to pandas
test = pd.DataFrame(results)
Value Error Traceback (most recent call last)
in ()
----> 1 test = pd.DataFrame(results)
in init(self, data, index, columns, dtype, copy)
420 dtype=values.dtype, copy=False) 421 else: 422 raise ValueError('DataFrame constructor not properly called!')
423
424 NDFrame.init(self, mgr, fastpath=True)
ValueError: DataFrame constructor not properly called!
如果使用DataFrames.jl包,则会出现错误(在Python中读取Julia数据帧)。但是,它似乎与Pandas.jl包配合得很好:
这在Win10、Python 3.8.2和Julia 1.3.1上进行了测试
相关问题 更多 >
编程相关推荐