我有一份附有提交日期的口述。我想计算一下每一次任务之间有多少天。现在我把日期放在一个列表中,但是当我想计算天数时,它会给我一个错误
我甚至试着用上一个日期填充emtpy点,这样它们之间的天数就可以是0。这也给了我下面看到的错误值
我现在使用的代码似乎是:
days_inbetween = []
for i in time_list:
index = time_list.index(i)
# print(index)
if i == '':
# print(i)
continue
else:
try:
days = datetime.strptime(time_list[index + 1], time_format) - datetime.strptime(i, time_format)
# print(days)
days_inbetween.append(days.days)
except:
days = datetime.strptime(time_list[-1], time_format) - datetime.strptime(i, time_format)
days_inbetween.append(days.days)
print(days_inbetween)
---------------------------------------------------------------------------------------------------------
This is the dictionary
from:
"User": {
"US01": "7-10-2020 05:49",
"US02": "8-10-2020 06:09",
"US03": "12-10-2020 06:05",
"US04": "14-10-2020 12:17",
"US05": "14-10-2020 12:17",
"US06": "21-10-2020 07:11",
"US07": "21-10-2020 07:11",
"US08": "23-10-2020 06:36",
"US09": "27-10-2020 06:42",
"US10": "27-10-2020 06:42",
"US11": "28-10-2020 08:28",
"US12": "",
"US13": "28-10-2020 08:28",
"US14": "",
"US15": "",
"US16": "",
"US17": "29-10-2020 16:22"
}
To:
"User": {
"US01": "3 days",
"US02": "2 days",
"US03": "2 days",
"US04": "0 days",
"US05": "6 days",
"US06": "0 days",
"US07": "1 days",
"US08": "4 days",
"US09": "0 days",
"US10": "1 days",
"US11": "0 days",
"US12": "not done",
"US13": "1 days",
"US14": "not done",
"US15": "not done",
"US16": "not done",
"US17": "1 days"
}
就像死神写的那样
您的日期中有4个空字符串,我为您标记了它们:
“ValueError:时间数据”与格式“%d-%m-%Y%H:%m”不匹配”
相关问题 更多 >
编程相关推荐