Search code examples
c#dataframedeedle

Deedle dataframe slicing by rows in C#


How do I slice by rows in a Deedle dataframe using C#? For example, I want the first three rows in a Deedle dataframe using C#.


Solution

  • In Deedle, you can slice the data frame based on the row keys or based on the offset. If you have, for example a frame of type Frame<DateTime, string> (with dates as the keys), you can write:

    var dfJanuary = df.Rows.Between(new DateTime(2015, 1, 1), new DateTime(2015, 2, 1));
    

    As for offsets, the current API is a bit ugly, but you can write:

    // First 10 rows
    df.GetAddressRange(RangeRestriction<long>.NewStart(10));
    // Last 10 rows
    df.GetAddressRange(RangeRestriction<long>.NewEnd(10));
    // Rows 10, 11, 12, .. , 19, 20
    df.GetAddressRange(RangeRestriction<long>.NewFixed(10, 20));
    

    We should really add Take extension method and a few others to make this easier.
    (Please open an issue or even better, send us a pull request that adds it somewhere here.)