2013-12-23 61 views
1

可以從IronPython有效使用Deedle嗎?這樣做可能看起來很不合時宜,但看起來讓大熊貓完全從IronPython工作可能會很困難 - 有一些使用IronClad的非活動移植項目和方法,但不清楚是否有人已經成功地完成了IronClad。使用像Deedle這樣的純.NET解決方案似乎是一條更好的途徑。從IronPython使用deedle

+0

你見過[這個答案](HTTP:// stackoverflow.com/a/14443106/468244)?看起來像熊貓一樣沒有... –

回答

0

Deedle是一個標準的.NET庫。我對IronPython的瞭解有限,但我認爲它可以讓你使用.NET語言 - 所以它也適用於Deedle。 Deedle文檔has a number of examples showing how to use it from C#,因此如果您知道如何使用IronPython中的其他.NET庫,則應該能夠將C#示例轉換爲IronPython。

0

我個人的經驗是,試圖讓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 dataframes,如:

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