def function_name(df):
for i, row in df.iterrows():
df.set_value(...)
return df
if __name__ == '__main__':
# Assume we have a dataframe called idf
idf = function_name(idf)
In the code above, I pass a dataframe called idf into a function called function_name. In that function, I loop over all rows in the dataframe, make some modifications and return a dataframe which I store back into idf.
I have a feeling that this approach is wasting memory, can someone correct me or point out a better more pythonic approach? Please note that I have a good reason to be using iterrows, even though it makes everything slower, I just want some feedback on the way I am passing dataframe to a function and getting it back
---EDIT--
Based on feedback esp by @marius, here's what I want to know:
By passing dataframe into the function, am I making a new copy of the dataframe? That is the memory wastage I am concerned with