如何避免这种熊猫数据帧处理的麻烦

在不使用iterrows()的情况下,将以下代码转换为更有效的代码时,需要一些帮助。

for index, row in df.iterrows():
alist=row['index_vec'].strip("[] ").split(",")
blist=[int(i) for i in alist]
for col in blist:
    df.loc[index, str(col)] = df.loc[index, str(col)] +1

上面的代码基本上读取'index_vec'列下的字符串,解析并转换为整数,然后为每个整数将关联的列增加一。输出示例如下所示:

enter image description here

以第0行为例。其字符串值为“ [370,370,-1]”。因此,以上代码将“ 370”列增加了2,将“ -1”列增加了1。输出显示被截断,因此仅显示“ -10”到“ 17”列。

使用iterrows()处理大型数据帧非常慢。我想获得一些帮助以加快速度。谢谢。