у меня есть датафрейм. Я применяю уникальный метод для одного столбца, но
for i in range(len(np.unique(first_group.Note_Detail))):
s=np.unique(first_group.Note_Detail)[i]
first_group.Insurance_Id[i]
t={}
for m in re.finditer(r'^(.+)(?:\r?\n\s*\[(.+)])?\r?$', s, re.M):
if m.group(2):
t1={}
for sub_item in [x.strip() for x in m.group(2).strip().split('], [') if ':' in x]:
itm=sub_item.split(':')
itm1=itm[1].strip().split('to')
t2={}
if len(itm1)>1:
t2['old']=itm1[0].strip()
t2['new']=itm1[1].strip()
t2['action']='Changed'
elif len(itm1)==1 and itm[1].strip()=='Removed':
t2['old']='Null'
t2['new']='Null'
t2['action']='Removed'
else:
t2['old']='Null'
t2['new']=itm1[0].strip()
t2['action']='added'
t1[itm[0].strip()]=t2
# t.append(t1)
t[m.group(1).strip().split(':')[0]]=t1
else:
t[m.group(1).strip().split(':')[0]]='None'
# print t
res[i]=[t,first_group.Insurance_Id[i],first_group.Patient_Id,first_group.Patient_Id,first_group.Created_By]
печать Res
KeyError Traceback (most recent call last)
<ipython-input-314-971c32825ccc> in <module>()
31 t[m.group(1).strip().split(':')[0]]='None'
32 # print t
---> 33 res[i]=[t,first_group.Insurance_Id[i],first_group.Patient_Id,first_group.Patient_Id,first_group.Created_By]
34 print res
/usr/local/lib/python2.7/dist-packages/pandas/core/series.pyc in __getitem__(self, key)
765 key = com._apply_if_callable(key, self)
766 try:
--> 767 result = self.index.get_value(self, key)
768
769 if not is_scalar(result):
/usr/local/lib/python2.7/dist-packages/pandas/core/indexes/base.pyc in
get_value (self, series, key)
3116 попробуй:
3117 вернуть self._engine.get_value (s, k,
-> 3118 tz = getattr (series.dtype, 'tz', None))
3119 кроме KeyError как e1:
3120, если len (self)> 0 и self.inferred_type в ['integer', 'boolean']:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
KeyError: 0
как получить индекс фрейма данных first_group для доступа к first_group.Insurance_Id[i]
внутри цикла