I have this code
def expander(dataframe, n):
d = dict(tuple(input_dataframe.groupby(input_dataframe.columns[0])))
u = input_dataframe['Type'].unique()
cols = ['Type', 'Variants']
df2 = pd.DataFrame(columns=cols, index=range(n))
for i in range(len(u)):
df2 = d[u[i]].copy()
df2["Variants"] = np.nan
df2
df3 = input_dataframe.append(df2, ignore_index=True)
print(df3)
When I run the code with :
expander(input_dataframe=pd.DataFrame({
'Type':['iPhone', 'iPhone', 'iPhone', 'iPhone', 'Samsung', 'Samsung', 'Samsung', 'Samsung'],
'Variants':['12 Mini', '12', '12 Pro', '12 Pro Max', 'S21 FE', 'S21', 'S21+', 'S21 Ultra']
}), n = 4)
I was expecting the output to be like this :
But instead, what I got was like this :
How can I solve this?
