刚开始学,不会做,用傻办法, 先全部列一边,再把重复的地方用for 循环写:
所有的名单都已name list 为准,向左合并,且序列排序也以name list为准:
list1 = [namelist,task,call,visit,leads,leads2_1,leads2_2,opp,qt1,qt2,opp2_qty,opp2_weighted]
c1 = pd.merge(namelist,task,left_index = True,right_index = True,how = 'left',sort = False)
for i in range(len(list1)):
if i < 10:
c1 = pd.merge(c1,list[i+2],left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,call,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,visit,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,leads,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,leads2_1,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,leads2_2,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,opp,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,qt1,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,qt2,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,opp2_qty,left_index = True,right_index = True,how = 'left',sort = False)
# c1 = pd.merge(c1,opp2_weighted,left_index = True,right_index = True,how = 'left',sort = False)
然后就出了报错,T-T, 天天报错…
TypeError: 'type' object is not subscriptable
报错原因:下标索引加的不对:查了下是list1在写for循环的是写成了list, 改成list1 就好了~