Python Script to loop through and create variables

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Regex - How to capture all iterations of a repeating pattern?