|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
问题:
运行finish_time = dt["信息归档完成时间"][i] - dt["业务受理接受时间"][i]出现错误,而运行finish_time = dt["信息归档完成时间"][i] - dt["业务受理完成时间"][i]没有问题,我都不知道怎么办?
代码:
- import pandas as pd
- # 打开合并后数据表
- df = pd.read_excel("01.xlsx")
- # 筛选出信息归档时间不为0的数据
- dt = df.loc[df["信息归档完成时间"] != 0]
- list_time = []
- for i in range(dt.shape[0]):
- finish_time = dt["信息归档完成时间"][i] - dt["业务受理接受时间"][i]
- list_time.append(finish_time)
- '''
- n = 0
- table = []
- sum_table = 0
- for each in list_time:
- [a,b] = str(each).split("days",1)
- table.append(a)
- sum_table += int(a)
- n += 1
- [a,b]=str(list_time[0])
- '''
- print(list_time)
复制代码
错误原因:
Traceback (most recent call last):
File "C:\Users\Chysial\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\indexes\base.py", line 3078, in get_loc
return self._engine.get_loc(key)
File "pandas\_libs\index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: '业务受理接受时间'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Chysial\Desktop\efficiency_analysis.py", line 8, in <module>
finish_time = dt["信息归档完成时间"][i] - dt["业务受理接受时间"][i]
File "C:\Users\Chysial\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 2688, in __getitem__
return self._getitem_column(key)
File "C:\Users\Chysial\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 2695, in _getitem_column
return self._get_item_cache(key)
File "C:\Users\Chysial\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 2489, in _get_item_cache
values = self._data.get(item)
File "C:\Users\Chysial\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\internals.py", line 4115, in get
loc = self.items.get_loc(item)
File "C:\Users\Chysial\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\indexes\base.py", line 3080, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\_libs\index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: '业务受理接受时间'
如果运行完成时间是对的,得出结果是:
[Timedelta('119 days 23:24:57'), NaT, Timedelta('134 days 22:58:20'), Timedelta('97 days 00:34:39'), NaT, NaT, Timedelta('99 days 03:51:44'), NaT]
谁能帮我解决一下什么问题啊,附件是excel,无法上传,这是
业务受理接收时间 业务受理完成时间 信息归档完成时间 受理时间
2017/11/21 8:43 2017/11/21 9:08 2018/3/21 8:33 2017/11/21 8:43
2017/12/4 14:59 2017/12/4 15:02 2017/12/4 14:59
2017/11/6 10:07 2017/11/6 10:30 2018/3/21 9:29 2017/11/6 10:07
2017/12/14 8:40 2017/12/14 9:23 2018/3/21 9:58 2017/12/14 8:40
2018/1/18 13:14 2018/1/18 13:19 2018/1/18 13:14
2017/10/25 9:45 2017/10/25 9:50 2017/10/25 9:45
2017/12/13 8:58 2017/12/13 9:12 2018/3/22 13:04 2017/12/13 8:58
2017/12/4 14:49 2017/12/4 14:54 2017/12/4 14:49
方向应该对了吧?
KeyError: 'the label [信息归档完成时间] is not in the [index]'
没有这一栏,看回 excel 里面有什么东西
|
|