How can i fix "InvalidIndexError: Reindexing only valid with uniquely valued Index objects" ?

3,199 views
Skip to first unread message

Ket s

unread,
Jun 17, 2018, 12:37:45 PM6/17/18
to PyData
I try to merge with code below:
MergeDf = pd.merge(Aydf, TMTdf[['Key_Cut', 'FSN', 'Status']],on= ['Key_Cut'], how= 'left', indicator=True)    

then found the issue as below:
---------------------------------------------------------------------------
InvalidIndexError                         Traceback (most recent call last)
<ipython-input-143-fec18cf94c76> in <module>()
     85 "Ay(&TMT) Merge DataFrame"
     86 "Match"
---> 87 BothMergeDf = pd.merge(Aydf, TMTdf[['Key_Cut', 'FSN', 'Status']],on= ['Key_Cut'], how= 'left',right_index=False, indicator=True)
     88 BothMergeDf.to_csv('D:...Ay&TMT_Merge.csv', index=False, encoding = "ISO-8859-1"and'utf-8-sig')
     89 "TMT NotMatch"

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
     56                          copy=copy, indicator=indicator,
     57                          validate=validate)
---> 58     return op.get_result()
     59 
     60 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in get_result(self)
    578         if self.indicator:
    579             self.left, self.right = self._indicator_pre_merge(
--> 580                 self.left, self.right)
    581 
    582         join_index, left_indexer, right_indexer = self._get_join_info()

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in _indicator_pre_merge(self, left, right)
    608     def _indicator_pre_merge(self, left, right):
    609 
--> 610         columns = left.columns.union(right.columns)
    611 
    612         for i in ['_left_indicator', '_right_indicator']:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexes\base.py in union(self, other)
   2237                 result.extend([x for x in other._values if x not in value_set])
   2238         else:
-> 2239             indexer = self.get_indexer(other)
   2240             indexer, = (indexer == -1).nonzero()
   2241 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_indexer(self, target, method, limit, tolerance)
   2685 
   2686         if not self.is_unique:
-> 2687             raise InvalidIndexError('Reindexing only valid with uniquely'
   2688                                     ' valued Index objects')
   2689 

InvalidIndexError: Reindexing only valid with uniquely valued Index objects
---------------------------------------------------------------------------

For more detail:

Aydf
          IDA pvncd lcnsid    lcnno drgtpcd rgttpcd  \
1    11961|0|0    10   1535  2800001       2   1A|1A   

                                       thargttpnm  \
1  ยามนุษย์ผลิตภายในประเทศ(แผนปัจจุบัน)(ยาเดี่ยว)   

                                          engrgttpnm GROUPNAME  \
1  LOCAL MANUFACTURED DRUG REGISTRATION FOR HUMAN...        DR   

  CITIZEN_AUTHORIZE     ...      blank4  blank5  blank6   blank7  blank8  \
1          1.06E+11     ...          mg       P                            

   blank9  blank10  blank11         \n     Key_Cut  
1                                   \n   1A 421/32  

[9 rows x 96 columns]


TMTdf
     KeyReg_TMT TPUCode                                   ActiveIngredient  \
1  2C 13/51(NC)  100005  alginic acid + aluminium hydroxide + magnesium...   

                 Strength       Dosageform Contvalue Contunit DispUnit  \
1  200 mg + 30 mg + 40 mg  chewable tablet                      tablet   

           TradeName                                Manufacturer  \
1            ALGYCON  "TAI YU CHEMICAL & PHARMACEUTICAL, TAIWAN"   

                                                 FSN Status    Key_Cut  
1  "ALGYCON (TAI YU CHEMICAL & PHARMACEUTICAL, TA...    0\n   2C 13/51  


Thank you in advance. :)


Reply all
Reply to author
Forward
0 new messages