I have a query. I understand that python passed by object (which I think is similar to passing by reference in C++). I have a function which I loop
def GrowListandShrinkDataFrame(DF, m_list, criteria):
FoundDF = DF[DF['Criteria'] == criteria ]
if not FoundDF.empty:
FoundDF['X1'] = FoundDF['X1'] - FoundDF['X2']
m_list.append(dict{'Criteria' : criteria,
'X1' : FoundDF['X1'],
'X2' : FoundDF['X2']})
droplist =DF.index[(DF['X1'] < 0)].tolist()
DF = DF.drop(droplist)
def main():
for rows in df.itertuples():
GrowListandShrinkDataFrame(df2, listA, rows[1])
print(len(listA))
print(df2.shape[0])
but this is the observation i get for each iteration
- The list grows in size
- Dataframe did not reduce in size
IS my understanding of pass by object wrong? Or some issue with my coding?
Thanks