我们可以在 .NET Ironpython 中加载 Pandas DataFrame 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14432059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:36:07  来源:igfitidea点击:

Can we load pandas DataFrame in .NET ironpython?

python.netpandasironpythonpython.net

提问by Alok

Can we load a pandas DataFrame in .NET space using iron python? If not I am thinking of converting pandas df into a csv file and then reading in .net space.

我们可以使用铁蟒在 .NET 空间中加载 Pandas DataFrame 吗?如果不是,我正在考虑将 pandas df 转换为 csv 文件,然后在 .net 空间中读取。

采纳答案by Jeff Hardy

No, Pandas is pretty well tied to CPython. Like you said, your best bet is to do the analysis in CPython with Pandas and export the result to CSV.

不,Pandas 与 CPython 有很好的联系。就像你说的,你最好的办法是用 Pandas 在 CPython 中进行分析并将结果导出到 CSV。

回答by Rafal Zajac

Regarding the option including serialization:

关于包括序列化的选项:

I'm still investigating similar case - we want to process the data in python and then use the results in c#. Our requirement was to (preferably) keep the python part platform independent so that we can run our number crunching on either linux or windows. Long story short we decided to use binary serialization/deserialization with Message Pack: http://msgpack.org/index.html

我仍在调查类似的案例——我们想在 python 中处理数据,然后在 c# 中使用结果。我们的要求是(最好)保持 python 部分平台独立,以便我们可以在 linux 或 windows 上运行我们的数字运算。长话短说,我们决定对 Message Pack 使用二进制序列化/反序列化:http: //msgpack.org/index.html

We convert the DataFrame values to list, and serialize to file:

我们将 DataFrame 值转换为列表,并序列化为文件:

import msgpack as mp
data_as_list = df.values.tolist()
mp.pack(data_as_list, open("d:\msgpack1.mp",'wb'))

Then on the C# side we use the .net implementation of MessagePack to deserialize the data:

然后在 C# 端,我们使用 MessagePack 的 .net 实现来反序列化数据:

using MsgPack;
var serializer =
   SerializationContext.Default.GetSerializer<MessagePackObject[][]>();
var unpackedObject = serializer.Unpack(File.OpenRead("d:\msgpack1.mp"));

Main advantages of binary serialization:

二进制序列化的主要优点:

回答by denfromufa

It is possible to call CPython from .NET using Python.NET:

可以使用 Python.NET 从 .NET 调用 CPython:

https://github.com/pythonnet/pythonnet/tree/develop

https://github.com/pythonnet/pythonnet/tree/develop