2016-06-14 141 views
0
系列

這個腳本語句字典不兼容索引:蟒蛇如果與

for x in df.index: 
    if df.loc[x,'medicament1'] in dicoprix: 
     df.loc[x,'coutmed1'] = dicoprix[df.loc[x,'medicament1']] 

給出了這樣的錯誤:

File "<ipython-input-35-097fdb2220b8>", line 3, in <module> 
    df.loc[x,'coutmed1'] = dicoprix[df.loc[x,'medicament1']] 

    File "//anaconda/lib/python2.7/site-packages/pandas/core/indexing.py", line 115, in __setitem__ 
    self._setitem_with_indexer(indexer, value) 

    File "//anaconda/lib/python2.7/site-packages/pandas/core/indexing.py", line 346, in _setitem_with_indexer 
    value = self._align_series(indexer, value) 

    File "//anaconda/lib/python2.7/site-packages/pandas/core/indexing.py", line 613, in _align_series 
    raise ValueError('Incompatible indexer with Series') 

ValueError: Incompatible indexer with Series 

但是腳本運行,這意味着df.loc[x,'coutmed1']需要我想要的價值。

我不明白我做錯了什麼?

我認爲這個問題來源於此

dicoprix[df.loc[x,'medicament1']] 

回答

0

當字典的關鍵是指多個值出現此問題!