I am very new to python and it's probably a simple question, but I cannot seem to find a solution.
I have several pandas data frames with names going like: output_1, output_2, ..., output_n
I want to sum their lengths (as in the number of their rows) and I came up with something like this:
sum =0
for num in range(1,n):
nameframe="output_"+str(num)
sum+=nameframe.shape[0]
The problem is that Python sees nameframe as a string, not as the name of a dataframe.
Looking around I found a potential solution:
sum =0
for num in range(1,n):
x = globals()["output_urls_%s" % num]
sum+=x.shape[0]
This seems to work, however the usage of globals() seem to be very discouraged. Therefore, what is the most pythonic way to achieve my purpose?
nameframe = eval("output_"+str(num))in the loop, but I agree with @FooBar you should be storing these as a list upon creation, or if you want to keep names use a dictionary.