Skip to content
Advertisement

Loop through a few commands using a function

I have a loop where I constantly got an error message.

JavaScript

I want to loop them through a function.

So far I have:

JavaScript

How can I number the df and let the df go through 1, 2, 3, 4 (like df1, df2 df3)

Advertisement

Answer

col is a variable. 'col' is a string. Having df['col'] doesn’t refer to the variable col.

Your string format is done wrong: col = "col{}_df".format(i)

Also, range(2,5) will give you [2,5) not [2,5]. It is not inclusive.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement