I have a dataframe in a similar format to the below;
Sites Points Value
ABC,DEF 2 10
GHI, JKL,MNO 4 15
I want to create new rows for each of the points, which I have been able to do with the following code (disclaimer: I found this code but can't find to reference);
def duplicate_rows(df, countcol):
for _, row in df.iterrows():
for i in range(int(row[countcol])-1):
df = df.append(row)
df.sort_index(inplace=True)
return df
df_dup = duplicate_rows(base_df,'Points')
This gives an output of
Sites Points Values
ABC, DEF 2 10
ABC, DEF 2 10
GHI, JKL, MNO 4 15
GHI, JKL, MNO 4 15
GHI, JKL, MNO 4 15
GHI, JKL, MNO 4 15
What I am trying to achieve is;
Sites Points Values
ABC 2 10
DEF 2 10
GHI 4 15
JKL 4 15
MNO 4 15
MNO 4 15
Any ideas on how this could be achieved?