I am working with groupby but i dont want to lose other columns which are not included in groupby such as i have a df:
id date name item price unit store
1 1/1/2020 abc apples 200 Fruits BigB
1 1/2/2020 abc apples 100 Fruits BigB
1 1/3/2020 abc apples 250 Fruits BigB
1 1/1/2020 abc mangoes 350 Fruits BigB
1 1/2/2020 abc mangoes 150 Fruits BigB
1 1/3/2020 abc mangoes 50 Fruits BigB
2 1/1/2020 xyz apples 50 Fruits BigB
2 1/2/2020 xyz apples 50 Fruits BigB
I want to create two columns of flag and start on basis of id and name and if the value of price is greater than its previous row then flag is 1 or else its 0.The data must be based on id,name and items.start column is based on flag.Initially start value will be its price value for the first row.If flag is 0 the start has the previous value and when flag is changed to 1 the start also changes to its corresponding price value The output will be:
id date name item price unit store Flag start
1 1/1/2020 abc apples 200 Fruits BigB 0 200
1 1/2/2020 abc apples 100 Fruits BigB 0 200
1 1/3/2020 abc apples 250 Fruits BigB 1 250
1 1/1/2020 abc mangoes 350 Fruits BigB 0 350
1 1/2/2020 abc mangoes 150 Fruits BigB 0 350
1 1/3/2020 abc mangoes 50 Fruits BigB 0 350
2 1/1/2020 xyz apples 50 Fruits BigB 0 50
2 1/2/2020 xyz apples 50 Fruits BigB 0 50
Groupby is done by id,name and item column.Thanks in advance.The df is sorted by id,name,item and date.