When you return
from the function, it's over.
You're out of the function and that's it.
You could use a generator to achieve what you want or you may return a tuple
or a list
.
Using a generator :
def fun(list_1):
for each_value in list_1:
# perform some operation and create a new data frame(pandas) named "new_data_frame" for each value in the list
print each_value
yield new_data_frame
for data_frame in fun(list_1):
# Do something with the data frame "data_frame"
This will print the value each time, and return your data frame.
But it returns a generator, so you have to call the function multiple times. What you cannot really do is get your data frames in a loop without wanting to store them in an list or assimilated or call the function only once.
A simpler way with a list could be:
def fun(list_1):
data_frames = []
for each_value in list1:
# perform some operation and create a new data frame(pandas) named "new_data_frame" for each value in the list
print each_value
data_frames.append(new_data_frame)
return data_frames
For reference, I'd suggest you have a look at What does the "yield" keyword do in Python?
which may be interesting for you.