Reputation: 864
I want to iterate through the rows in a DataFrame and perform the df.columnB.diff()
method only if the current row and the next row have the same string in df['columnA']
.
How can I do this?
Upvotes: 0
Views: 39
Reputation: 323366
You are looking for groupby
df['New']=df.groupby('columnA')['columnB'].diff()
Upvotes: 1