我正在寻找一种更有效的方法来执行检查,然后在必要时应用转换。
这是我当前的代码
for i in tqdm(df.index):
if df.loc[i,'WHP Total Acres'] > df.loc[i,'GIS_ACRES']:
conv_factor = (df.loc[i,'GIS_ACRES'])/(df.loc[i,'WHP Total Acres'])
df.loc[i,'Very Low'] = df.loc[i,'Very Low'] * conv_factor
df.loc[i,'Low'] = df.loc[i,'Low'] * conv_factor
df.loc[i,'Moderate'] = df.loc[i,'Moderate'] * conv_factor
df.loc[i,'High'] = df.loc[i,'High'] * conv_factor
df.loc[i,'Very High'] = df.loc[i,'Very High'] * conv_factor
else:
df.loc[i, 'WHP Total Acres'] = df.loc[i,'WHP Total Acres']
要遍历 350K 记录,这在我的机器上大约需要 2 个小时。我确信必须有一种更有效的方法。