I want to use pandas apply () instead of iterating over each row of the data frame, which, as far as I know, is a more efficient procedure.
What I want to do is simply:
temp_arr = [0,1,2,3]
temp_df is a 4x4 dataframe, simply: [[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]]
For each row in my temp_df, minus the corresponding number in the temp_arr.
So, for example, the first line in my data frame is [1,1,1,1], and I want to minus the first element in my temp_arr (which is 0) of them, so the output should be [1, 1,1,1 ]. The second line is [2,2,2,2], and I want to minus the second element in temp_arr (which is 1) of them, so the output should also be [1,1,1,1].
If I subtract a constant number, I know that I can easily do this with:
temp_df.apply(lambda x: x-1)
But the tricky thing here is that I need to go through my temp_arr to get a subtracted number. Anyway, can I do this with apply ()?