问题描述
所以我得到了一个像这样的字典:
{2321: datetime.datetime(2015, 2, 16, 11, 55, 50, 414175, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2322: datetime.datetime(2015, 2, 16, 13, 10, 17, 338086, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2323: datetime.datetime(2015, 2, 16, 13, 12, 30, 847941, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2324: datetime.datetime(2015, 2, 16, 13, 15, 14, 803438, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2325: datetime.datetime(2015, 2, 16, 13, 17, 42, 749529, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2326: datetime.datetime(2015, 2, 16, 13, 19, 58, 757024, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2327: datetime.datetime(2015, 2, 16, 13, 22, 16, 554052, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2328: datetime.datetime(2015, 2, 16, 13, 26, 56, 4452, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2081: datetime.datetime(2015, 1, 27, 10, 28, 10, 695887, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2082: datetime.datetime(2015, 1, 27, 10, 35, 34, 71091, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>),
2083: datetime.datetime(2015, 1, 27, 10, 40, 1, 436955, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>)}
其{ticketID:ticketDateTime}
我想使用.isocalendar从DateTime对象获取calendarweeks(因为我需要每周计算票数)
我考虑过要创建一个长度为52的零填充数组(因为一年有52周),然后使用forloop遍历字典,并始终向该日历周的索引添加1。
抱歉,我是python的新手,将尝试向您展示C#中的一些代码,我认为它如何工作:
int[] resultsArray = new int[52]
for(int i = 0; i<= myDictionary.Length; i++){
index = myDictionary[i].isocalendar()[1]
resultsArray[index] = resultsArray[index]+1}
1楼
您可以使用Counter
来执行此操作。
c = Counter()
for d in dates:
c[d.week] += 1 # note I don't know the syntax for week off the top of my head
2楼
尝试这个:
ClosedList = [0] * 53
OpenList = [0] * 53
OpenedList = [0] * 53
def CreateKWlist():
for i in ClosedDict:
for j,k in ClosedDict[i]['prio-events']:
if j.isocalendar()[0] == 2015:
index = j.isocalendar()[1]
ClosedList[index] += 1
OpenedList[index] += 1
break
for i in OpenDict:
for j,k in OpenDict[i]['prio-events']:
if j.isocalendar()[0] == 2015:
index = j.isocalendar()[1]
OpenList[index] += 1
OpenedList[index] += 1
break