Python Script to loop through and create variables

Multi tool use


Python Script to loop through and create variables
I have a massive block of code that creates the following arrays (Var1 ... Var100). I was wondering if there is way to actually write a python script to create and execute the code within a for loop. However, I've been unsuccessful so far in doing so.
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)
I've tried the following but doesn't work:
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)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.