how to convert row into a dimension under condition?
row 0, and row 3 are category total
current format
import pandas as pd
data = [['FRUIT', 'FRU', 100],['A.GRAPE','A.GRA', 50],['A.APPLE','A.APP', 50],
['VEGETABLE', 'VEG', 75],['A.TOMATO','A.TOM', 25],['A.CABBAGE','A.CAB', 25],['A.CARROT','A.CAR', 25]]
df = pd.DataFrame(data, columns = ['name', 'abbrevation', 'value'])
df.head(10)
desired format
data2 = [['FRUIT','FRU','A.GRAPE','A.GRA', 50],['FRUIT','FRU','A.APPLE','A.APP', 50],
['VEGETABLE','VEG','A.TOMATO','A.TOM', 25],['VEGETABLE','VEG','A.CABBAGE','A.CAB', 25],['VEGETABLE','VEG','A.CARROT','A.CAR', 25]]
df2 = pd.DataFrame(data2, columns = ['category','category abbrevation','name', 'abbrevation', 'value'])
df2.head(10)
*row number under category may differ
i had check forum, nothing seems near
tried refer to this @https://stackoverflow.com/questions/62626290/how-to-merge-every-3-rows-of-a-dataframe-into-1-row-with-3-columns
but that's different, may i know how to achieve the desired format?
thanks

