10

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.

denfromufa
  • 5,610
  • 13
  • 81
  • 138
Alok
  • 3,160
  • 3
  • 28
  • 47

3 Answers3

10

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.

Jeff Hardy
  • 7,632
  • 24
  • 24
  • 1
    Pandas relies on numpy, which to my knowledge has a pretty solid port to IronPython by now. But it also depends on Cython and C for achieving high performance, right? The latter is probably the big problem, not numpy. – Bjarke Ebert Apr 22 '13 at 12:52
3

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

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

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:

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

Main advantages of binary serialization:

Rafal Zajac
  • 1,613
  • 1
  • 16
  • 13
1

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

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

denfromufa
  • 5,610
  • 13
  • 81
  • 138