Search code examples
c#deedle

Truncate/delete first x rows from a Frame


I have a Frame<int, string> which consists of a OHLCV data. I'm calculating technical analysis indicators for that Frame and since the first few records aren't accurate due to the fact that there are at the very begin, I have to remove them. How do I do that?

public override Frame<int, string> PopulateIndicators(Frame<int, string> dataFrame)
{
    var candles = dataFrame.Rows.Select(kvp => new Candle
    {
        Timestamp = kvp.Value.GetAs<DateTime>("Timestamp"),
        Open = kvp.Value.GetAs<decimal>("Open"),
        High = kvp.Value.GetAs<decimal>("High"),
        Low = kvp.Value.GetAs<decimal>("Low"),
        Close = kvp.Value.GetAs<decimal>("Close"),
        Volume = kvp.Value.GetAs<decimal>("Volume")
    }).Observations.Select(e => e.Value).ToList<IOhlcv>();
    
    // TODO: Truncate/remove the first 50 rows
    
    dataFrame.AddColumn("Rsi", candles.Rsi(14));
}

Solution

  • Most operations in Deedle are expressed in terms of row keys, rather than indices. The idea behind this is that, if you work with ordederd data, you should have some ordered row keys.

    This means that this is easier to do based on row keys. However, if you have an ordered row index, you can get a key at a certain location and then use it for filtering in Where. I would try something like:

    var firstKey = dataFrame.GetRowKeyAt(50);
    var after50 = dataFrame.Where(kvp => kvp.Key > firstKey);