How to apply changes in for loops to be kept outside of for loop too?
I have a dataframe that is read inside a for loop via a function and and after bunch of computation, I apply a filter command over it and hope to have the changed dataframe for the next iterations of for loop. But the dataframe df does not change. How can I ask julia to keep changes and read the chnaged df at each iteration?
for i in I
# read df
# do some computation...
elements= find_removeable_indices(x) # this function returns some indices that we want to remove from df later
# do some other computation...
filter!(row -> (row.Index ∉ elements) && row.Price >= current_Price + shift , df) # df is the original dataframe with 1000 rows and 50 columns. One of the columns is `index`, the other is `Price` and shift is a constant
Maybe a clean way to do this would be to put the for loop in a function that gives the data frame as return value. But it would help if you could give a complete example: in your code example it’s not clear where the df variable is defined and where it’s used.
@sijo The df is defined outside of this for loop and it is read from a csv file.
My understanding of ! is that it should change anything regardless of its local domain. Is that right?
And filter should return those rows from df that met the condition. In this case return those rows in df where their index columns are not in elements and also their price are greater than the current shifted price. Is this a correct interpretation?
Is there any alternative to filter to allow for removing some rows from a dataframe?