安装最新版本的pandas 0.9.0以防这是一个错误。编辑:忘了提到这是Python 2.7。 试图阅读Excel文件。那部分似乎没问题。 最初,我正在为pandas数据帧的每一行尝试iteritems(),因为id_company必须针对mysql数据库进行验证(代码不包括在内)。将它放入元组的相同/类似错误消息(代码如下)。错误信息如下。
注意有一个.reindex(),但它之前也没有用。 reindex()有点像冰雹。
作为解决方法,我可能只是从我的目标sql导入并进行连接。由于数据集的大小,我很担心。
import pandas as pd
def runNow():
#identify sheet
source = 'C:\Users\jlalonde\Desktop\startup_geno\startupgenome_w_id_xl_20121109.xlsx'
xls_file = pd.ExcelFile(source)
sd = xls_file.parse('Sheet1')
source_u = sd.drop_duplicates(cols = 'id_company', take_last=False)
source_r = source_u[['id_company','id_good','description', 'website','keyword', 'company_name','founded_month', 'founded_year', 'description']]
source_i = source_r.reindex() #hail mary
tup_r = [tuple(x) for x in source_i.values]
这是错误:
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
sg_sql_2.runNow()
File "sg_sql_2.py", line 31, in runNow
tup_r = [tuple(x) for x in source_r.values]
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 1443, in as_matrix
return self._data.as_matrix(columns).T
File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 723, in as_matrix
mat = self._interleave(self.items)
File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 743, in _interleave
indexer = items.get_indexer(block.items)
File "C:\Python27\lib\site-packages\pandas\core\index.py", line 748, in get_indexer
raise Exception('Reindexing only valid with uniquely valued Index '
Exception: Reindexing only valid with uniquely valued Index objects
所以,在这一天的大部分时间里,我的头靠在墙上,有人可以告诉我这是一个错误还是我错过了一些非常明显的东西?