安装最新版本的 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
所以,在一天的大部分时间里,我的头撞在墙上之后,谁能告诉我这是一个错误还是我错过了一些非常明显的东西?