首页 > 解决方案 > Python Pandas 中将数据框/列归零的最快方法

问题描述

有没有比像这样遍历数据框更快的方法来清零 pandas 数据框列(其中 A、B 和 C 是列名):

while x < Framelength
   dg.iloc[x, A] = 0
   dg.iloc[x, B] = 0
   dg.iloc[x, C] = 0
   x+=1

如果这样更快的话,我可以将整个数据帧归零

标签: pythonpandas

解决方案


检查与

cols=[...]
df.loc[:, cols]=0

推荐阅读