Home > Enterprise >  Is it possible to have multi-level column frame using deedle?
Is it possible to have multi-level column frame using deedle?

Time:03-19

I know it is possible to have multi-level index Frame in deedle, but is it also possible to have at the same time multi-level column as for example it is the case using Pandas library in Python. For example, I would like to achieve something like:

enter image description here

I tried to pass a tuple for the column as it is the case for multi-level index but the following is not working:

dfRes.AddColumn(("Country 1", "Region 1"), data.ToOrdinalSeries());

Any help would be greatly appreciated !

CodePudding user response:

Deedle uses the older Tuple type for this that was available prior to C# 7 and is the type used for tuples in F#. So, you can get this to work, but you just need to use the old-style C# Tuple. Deedle comes with a Tuple.Create helper to make this a bit easier:

var dfRes = Frame.CreateEmpty<int, Tuple<string, string>>();
dfRes.AddColumn(Tuple.Create("Country 1", "Region 1"), new[] { 1, 2, 3 });
dfRes.Print();

That said, I would consider to what extent this is actually needed - for multi-level row keys, you typically do that so that you can do some fancy aggregation. If this is just for presentation, it may just be easier to use a string encoding like "Country 1.Region 1".

  • Related