图像被添加,这样你就可以看到我的dataframe df2的样子 我写了一个代码来检查条件,如果匹配,它将更新我的列表中的项目,但它在所有工作,它返回我相同的未更新或相同的前一个列表。这个代码是错的吗? 请建议
emp1=[]
for j in range(8,df.shape[0],10):
for i in range(2,len(df.columns)):
b=df.iloc[j][3]
#values are appended from dataframe to list and values are like['3 : 3','4 : 4',.....]
ess=[]
for i in range(df2.shape[0]):
a=df2.iloc[i][2]
ess.append(a) #values taken from file which are(3,4,5,6,7,8,....etc i.e unique id number)
nm=[]
for i in range(df2.shape[0]):
b=df2.iloc[i][3]
nm.append(b) #this list contains name of the employees
ap= [i.split(' : ', 1)[0] for i in emp1] #split it with ' : ' and stored in two another list(if 3 : 3 then it will store left 3)
bp= [i.split(' : ', 1)[1] for i in emp1] #if 3 : 3 the it will store right 3
cp=' : '
#the purpose is to replace right 3 with the name i.e 3 : nameabc and then again join to the list
for i in range(len(emp1)):
for j in range(len(ess)):
#print(i,j)
if ap[i]==ess[j]:
bp[i]=nm[j]
for i in range(df.shape[0]):
ap[i]=ap[i]+cp # adding ' : ' after left integer
emp = [i + j for i, j in zip(ap, bp)] # joining both the values
预期的输出: 如果emp1包含3:3 然后在处理后应该显示像3:nameabc 问题来源StackOverflow 地址:/questions/59386144/how-to-update-replace-list-items-inside-a-nested-loop-after-matching-the-conditi
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
你好,我是AI助理
可以解答问题、推荐解决方案等