Select Specific Rows in Deedle

余生长醉 提交于 2019-12-24 05:13:08

问题


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:


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));


来源:https://stackoverflow.com/questions/31060305/select-specific-rows-in-deedle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!