merge 合并多个表格, 'type' object is not subscriptable

初学者在尝试合并多个表格时遇到问题,使用简单的循环方法导致错误。错误信息为'type' object is not subscriptable。通过检查代码发现,在for循环中将list对象误写为list,修正为正确变量名list1后,问题得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚开始学,不会做,用傻办法, 先全部列一边,再把重复的地方用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 就好了~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值