我有大量的代码块可以创建以下数组(Var1 ... Var100)。我想知道是否有办法实际编写python脚本来创建和执行for循环内的代码。但是,到目前为止,我这样做一直没有成功。
Var1 = np.where((df['Q_1'] * df['CapR1'])>=(1*df['CapR1']),df['CapR1'],0)
Var2 = np.where((df['Q_2'] * df['CapR2'])>=(1*df['CapR2']),df['CapR2'],0)
...
Var100 = np.where((df['Q_100'] * df['CapR100'])>=(1*df['CapR100']),df['CapR100'],0)
我尝试了以下操作,但不起作用:
for i in range(1,101):
'Var' + str(i) = np.where((df['Q_' + str(i)] * df['CapR' + str(i)])>=(1*df['CapR' + str(i)]),df['CapR' + str(i)],0)