我个人的经验是,试图让 Pandas 等 CPython 库在 Ironpython 上工作是一条死路。虽然there is a way to do it,但是非常不稳定,不可靠。
Deedle 似乎是下一个显而易见的选择,而且它确实有效。您只需要添加对程序集的引用,并注意 IronPython 如何处理泛型参数。
import clr;
import random;
from System import Tuple;
import itertools;
clr.AddReferenceToFileAndPath ("C:\\temp\\testedeedle\\packages\\FSharp.Core\\lib\\net40\\FSharp.Core.dll")
clr.AddReferenceToFileAndPath ("C:\\temp\\testedeedle\\packages\\Deedle\\lib\\net40\\Deedle.dll")
from Deedle import *
那么你可以使用现有的 Api 创建数据帧,例如:
myPythonList = [("ID1", 1.1, 1.2),
("ID2", 1.1, 1.2),
("ID3", 1.1, 1.2),
("ID4", 1.1, 1.2)];
values = [[Tuple.Create[str,str,float](x[0], "FirstValue", x[1]), Tuple.Create(x[0], "SecondValue", x[2])] for x in myPythonList]
tupleList =list((itertools.chain(*values)))
frame = Frame.FromValues[str,str,float](tupleList);
FrameExtensions.Print(frame);
series_mult = frame.FirstValue + frame.SecondValue
print (series_mult)
frame2 = frame * 2
FrameExtensions.Print(frame2);
产量...
FirstValue SecondValue
ID1 -> 1.1 1.2
ID2 -> 1.1 1.2
ID3 -> 1.1 1.2
ID4 -> 1.1 1.2
series [ ID1 => 2.3; ID2 => 2.3; ID3 => 2.3; ID4 => 2.3]
FirstValue SecondValue
ID1 -> 2.2 2.4
ID2 -> 2.2 2.4
ID3 -> 2.2 2.4
ID4 -> 2.2 2.4