I have a dataframe with columns that include part_id and transaction_qty that are sorted by the part_id and then the date that the transaction will occur.
I would like to add a column balance that would run logic like the below. But I am not sure how to call the function so it loops through the dataframe.
For row in dataframe (what is the correct syntax here?):
If part_id for this row index == part_id for the row index before:
this row balance = balance of the row index before + transaction_qty of this row index
else balance = transaction_qty of this row
I have a feeling this is far simpler than I’m thinking it is, but I’ve not found anything in the pandas documentation yet that seems to answer the question