【发布时间】:2020-08-20 05:23:45
【问题描述】:
我有以下数据。
new Dictionary<DateTime, Dictionary<string, int>>()
{
{
new DateTime(2020,05,05,10,10,10) ,
new Dictionary<string, int>()
{
{ "Value1", 2 },
{ "Value2", 4 },
{ "ValueXY", 6 },
}
},
{
new DateTime(2020,05,05,10,10,12) ,
new Dictionary<string, int>()
{
{ "Value1", 4 },
{ "Value2", 6 },
{ "ValueABC", 12 }
}
}
};
我想用 LINQ 做的是按 DateTime 分组,没有秒数,每分钟有一个包。添加单个键的平均值。
所以通过上面的例子,我会得到这个
new Dictionary<DateTime, Dictionary<string, int>>()
{
{
new DateTime(2020,05,05,10,10,0) ,
new Dictionary<string, int>()
{
{ "Value1", 3 },
{ "Value2", 5 },
{ "ValueABC", 12 },
{ "ValueXY", 6 }
}
}
};
我能够进行分组,但我没有得到平均部分的工作。
categorie.Value.GroupBy(row => row.Key.AddSeconds(-row.Key.Second));
任何想法如何做到这一点?
【问题讨论】:
标签: c# linq dictionary nested