2012-11-12 52 views
4

安装最新版本0.9.0熊猫的情况下,这是一个错误。编辑:忘了提及这是Python 2.7。 试图读取Excel文件。这部分似乎没问题。 本来,我是想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 

所以,对于这个敲打我的头靠在墙上一天的大部分时间后,谁能告诉我,如果这是一个错误,或者如果我我错过了真正明显的东西?

+0

可能的重复数据删除:http://stackoverflow.com/questions/13292944/resample-non-unique-time-indexes-in-python。你有没有可以用来重现错误的例子? – Garrett

+0

我可以发布excel文件没问题。不,这不是重复的,因为我有一个唯一索引和其他链接索引被复制......虽然该解决方案可以是相同的.... –

+0

GitHub的问题跟踪此错误:https://github.com/pydata /熊猫/问题/ 2236 – Garrett

回答

相关问题