Select Specific Rows in Deedle

1.4k views Asked by At

I have a deedle data frame, called df, with one of the columns named TimeSpent.

I would like to keep the rows, which have values for TimeSpent greater than a specific TimeSpan (e.g. 30 minutes). I could only manage to keep the rows with a specific TimeSpan (30 min) by using FilterRowsBy()

df = df.FilterRowsBy<int, string, TimeSpan>("TimeSpent", new TimeSpan(0, 30, 0));

How do you filter a deedle data frame for a certain range?

UPDATE: So, I decided to try to sort the deedle frame by TimeSpan first, and then slice it.

Frame<TimeSpan, string> dfTest = df.IndexRows<TimeSpan>("TimeSpent").SortRowsByKey();
var dfTest2 = dfTest.Rows.After(twentyMin);

And as a result I get a new data frame that is type <TimeSpan, ObjectSeries<System.String>>, but I need to convert this data frame to <TimeSpan, String>, and I do not know how.

1

There are 1 answers

1
alexshchep On BEST ANSWER

I ended up using linq to sort the data frame, after creating a new index by TimeSpan.

Frame<TimeSpan, string> dfResult =
    df.IndexRows<TimeSpan>("TimeSpent")
    .Where(kvp => kvp.Key > new Timespan(0, 20, 0));