这是我的输入:
ClientData = {
'ClientName1': {
'aggregate_PageviewsByWeek': [('2013-01-06', 2),
('2013-02-03', 1),
('2013-02-10', 1),
('2013-02-24', 1),
('2013-03-03', 2),
'aggregate_Pageviews_VisitsByWeek': [],
'aggregate_VisitsByWeek': [('2013-03-03', 1),
('2013-05-12', 1)]
},
'ClientName2': {
'aggregate_PageviewsByWeek': [('2013-01-06', 2),
('2013-02-03', 1),
('2013-02-10', 1),
('2013-02-24', 1),
('2013-03-03', 2),
('2013-03-24', 1),
],
'aggregate_Pageviews_VisitsByWeek': [],
'aggregate_VisitsByWeek': [('2013-03-03', 1),
('2013-03-31', 1),
('2013-05-12', 1),
('2013-05-19', 2),
('2013-06-30', 2)]
}
}
如何根据日期键将 'aggregate_PageviewsByWeek' 和 'aggregate_VisitsByWeek' 的并集附加到键 'aggregate_Pageviews_VisitsByWeek'
输出将类似于以下内容:
{
'ClientName1': {
'aggregate_PageviewsByWeek': [('2013-01-06', 2),
('2013-02-03', 1),
('2013-02-10', 1),
('2013-02-24', 1),
('2013-03-03', 2)],
'aggregate_Pageviews_VisitsByWeek': [
('2013-01-06', 2, 0),
('2013-02-03', 1, 0),
('2013-02-10', 1, ),
('2013-02-24', 1, 0),
('2013-03-03', 2, 1),
('2013-05-12', 0, 1)],
'aggregate_VisitsByWeek': [('2013-03-03', 1),
('2013-05-12', 1)]
},
'ClientName2': {
'aggregate_PageviewsByWeek': [('2013-01-06', 2),
('2013-02-03', 1),
('2013-02-10', 1),
('2013-02-24', 1),
('2013-03-03', 2),
('2013-03-24', 1)],
'aggregate_Pageviews_VisitsByWeek': [
('2013-01-06', 2, 0),
('2013-02-03', 1, 0),
('2013-02-10', 1, 0),
('2013-02-24', 1, 0),
('2013-03-03', 2, 1),
('2013-03-31', 1, 1),
('2013-05-12', 0, 1),
('2013-05-19', 0, 2),
('2013-06-30', 0, 2)],
'aggregate_VisitsByWeek': [('2013-03-03', 1),
('2013-03-31', 1),
('2013-05-12', 1),
('2013-05-19', 2),
('2013-06-30', 2)]
}
}
如果“在这种情况下的日期”键不在另一个列表中,我想将该值替换为 0 (Date, aggregate_PageviewsByWeek_Value, aggregate_VisitsByWeek_Value )
示例:
aggregate_PageviewsByWeek :('2013-01-06', 12)
和 aggregate_VisitsByWeek :(2013-01-13, 30)
输出将是:
aggregate_Pageviews_VisitsByWeek :[('2013-01-06', 12, 0), (2013-01-13, 0, 30)]
我这个问题的目标是根据日期获取页面浏览量和访问量的趋势。
谢谢!