I have a data frame that looks like below:
import pandas as pd
import numpy as np
df = pd.DataFrame({'id':[1,2,3],'class':[7,5,3], 'grades':[[4,5,6],[8],[]]})
what I am trying to do here is that I want to duplicate each row for the number of element in the list in "grades" column.
It is kind of hard to explain, so it will be better to show the desired output.
output = pd.DataFrame({'id':[1,1,1,2,3],'class':[7,7,7,5,3], 'grades':[4,5,6,8, np.nan]})
I have look through some solutions, but could not figure out a way.
It will be great if someone can provide a guidance.