I have a pandas dataframe something like this( much large in reality and it wouldn’t fit on this editor.
NAME ID_DES ID
ZZ11 FISH 1
ZZ22 FISH 1
ZZ33 FISH 1
ZZ44 FISH 1
XX11 CHIPS 2
XX22 CHIPS 2
XX23 CHIPS 2
XX24 CHIPS 2
YY11 SOUP 3
YY12 SOUP 3
YY13 SOUP 3
YY14 SOUP 3
What I am trying to achieve is to insert 3 rows before the start of each group. The groups are determined by ID or ID_DES.
I have success with grouping the df and exporting to excel…
df.groupby(‘ID’)
But not inserting new rows. Ideally i would ike these values to be inserted
“Desc:” with value from ID
“Header1:” with value from ID_DES
“Header2:” with values of both ID and ID_DES.
So the output DF would look like this…
NAME ID_DES ID
"Desc: FISH" FISH 1
"Header1: 1" FISH 1
"Header2: FISH1 " . FISH 1
ZZ11 FISH 1
ZZ22 FISH 1
ZZ33 FISH 1
ZZ44 FISH 1
"Desc: CHIPS" CHIPS 2
"Header1: 2" CHIPS 2
"Header2: CHIPS 2 " CHIPS 2
XX11 CHIPS 2
XX22 CHIPS 2
XX23 CHIPS 2
XX24 CHIPS 2
"Desc: SOUP" SOUP 3
"Header1: 3" SOUP 3
"Header2: SOUP 3" . SOUP 3
YY11 SOUP 3
YY12 SOUP 3
YY13 SOUP 3
YY14 SOUP 3