I am trying to understand how different type of iterations work in Python
For example following line will go through every line of dataframe all of the data frames
portfolio_pnl = (
(aapl_position - aapl_position.shift())
+ (amzn_position - amzn_position.shift())
)
Yet in the following situation, one has to use apply to ensure that a function is applied to every line
s = pd.read_csv("stock.csv", squeeze = True)
#### adding 5 to each value
new = s.apply(lambda num : num + 5)
So my question is: Where and how would one know to use apply
or any other loop and where would one can just need to use a formula and expect that to be applied on every line by itself.