df
fruit year price index_value Boolean index
apple 1960 11
apple 1961 12 100 True
apple 1962 13
apple 1963 13 100 True
banana 1960 11
banana 1961 12
How could I calculate the index column for the year after a True per fruit? The base year is given by the rows where index_value==100
I tried:
df['index'] = df.groupby('fruit')['price'].apply(lambda x: (x/x.iloc[0] * 100).round(0))
Expected Output:
fruit year price index_value Boolean index
apple 1960 11
apple 1961 12 100 True 100
apple 1962 13 108
apple 1963 13 100 True 100
apple 1964 11 84
banana 1961 12