Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we load pandas DataFrame in .NET ironpython?

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.

like image 944
Alok Avatar asked Jan 21 '13 03:01

Alok


People also ask

Can you use pandas in IronPython?

Short answer: No.

How do I import a DataFrame into a csv file?

By using pandas. DataFrame. to_csv() method you can write/save/export a pandas DataFrame to CSV File. By default to_csv() method export DataFrame to a CSV file with comma delimiter and row index as the first column.

Which library is used for DataFrame?

Pandas is a Python library. Pandas is used to analyze data.


2 Answers

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.

like image 167
Jeff Hardy Avatar answered Sep 28 '22 17:09

Jeff Hardy


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:

  • is less prone to any encoding related issues comparing to text based serialization formats like csv, json or xml
  • depending on the data it can be faster than CSV (it was in our case):http://matthewrocklin.com/blog/work/2015/03/16/Fast-Serialization/
like image 29
Rafal Zajac Avatar answered Sep 28 '22 18:09

Rafal Zajac