- 帖子
- 2
- 精华
- 0
- 积分
- 11
- 阅读权限
- 10
- 注册时间
- 2018-7-22
- 最后登录
- 2018-10-12
|
# -*- coding:UTF-8 -*-
import pandas as pd
import xlrd
df = pd.read_excel('ex1.xls',encoding = 'gb2312',skiprows=[0,1]) #读取xls文件,转码为gb2312
df1 = xlrd.open_workbook('ex1.xls')
print df.shape #显示数据的行与列数
#print df.dtypes #查看数据格式dtpyes
print df.columns #查看列名
print df.info() # 数据表信息
print df['初始接待客服']
代码如上,本人小白一枚,跟着论坛课程自学了一段时间,现在自己尝试做个小的excel调用的数据处理程序,但是在调用这块就卡住了
在python3的环境下测试代码可以调取出来中文名称的列数据,但是python2.7环境下一直失败,希望论坛大佬赐教,如何能成功解码,跪谢
excel表部分数据如下:
网站商务通 历史记录报表 | | 设定的条件如下:时间段: 从2018/10/5 0:00:00到2018/10/6 0:00:00 | 初始接待客服 | 开始访问时间 | 对话类型 | 8158 | 2018/10/5 23:56:29 | 较好对话 | 8158 | 2018/10/5 23:55:52 | 较好对话 | 8158 | 2018/10/5 23:45:40 | 较好对话 | 8158 | 2018/10/5 23:41:16 | 较好对话 | 8158 | 2018/10/5 23:40:54 | 较好对话 | 8158 | 2018/10/5 23:33:54 | 较好对话 | 8158 | 2018/10/5 23:23:45 | 一般对话 | 8158 | 2018/10/5 23:15:22 | 较好对话 | 8563 | 2018/10/5 23:04:34 | 较好对话 | 8158 | 2018/10/5 23:04:20 | 较好对话 |
错误信息:
E:\Python27\lib\site-packages\pandas\core\indexes\base.py:2037: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
return key in self._engine
E:\Python27\lib\site-packages\pandas\core\indexes\base.py:2057: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
return key in self._engine
E:\Python27\lib\site-packages\pandas\core\indexes\base.py:3078: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
return self._engine.get_loc(key)
E:\Python27\lib\site-packages\pandas\core\indexes\base.py:3080: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
return self._engine.get_loc(self._maybe_cast_indexer(key))
Traceback (most recent call last):
File "E:/Python27/��ϰ/analysis/��дexcel.py", line 16, in <module>
print df['初始接待客服']
File "E:\Python27\lib\site-packages\pandas\core\frame.py", line 2688, in __getitem__
return self._getitem_column(key)
File "E:\Python27\lib\site-packages\pandas\core\frame.py", line 2695, in _getitem_column
return self._get_item_cache(key)
File "E:\Python27\lib\site-packages\pandas\core\generic.py", line 2489, in _get_item_cache
values = self._data.get(item)
File "E:\Python27\lib\site-packages\pandas\core\internals.py", line 4115, in get
loc = self.items.get_loc(item)
File "E:\Python27\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: '\xe5\x88\x9d\xe5\xa7\x8b\xe6\x8e\xa5\xe5\xbe\x85\xe5\xae\xa2\xe6\x9c\x8d'
Process finished with exit code 1
|
|