Python Forum

Full Version: How to generate rows based on values in a column to fill missing values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to generate new rows based on values in a certain column. In current data as you can see 'days_left' column does not have all sequential values.

current = {'assignment': [1,1,1,1,2,2,2,2,2], 'days_left': [1, 2, 5, 9,1, 3, 4, 8, 13]}
dfcurrent = pd.DataFrame(data=current)
dfcurrent


While I want to generate rows into that dataframe to create make sequential list for for 'days_left' for each 'assignment'. Please see the desidered output below:


desired = {'assignment': [1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2],
'days_left': [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,10,11,12,13]}
dfdesired = pd.DataFrame(data=desired)
dfdesired


Note: The original data is much bigger and has other columns as well but I just simplified it for this question.

Could you please help me how I can solve this?

Thank you very much in advance!
Please note that you need to make an effort, we will be glad to help, but cannot write it for you.
Give it a go, and come back with specific questions when (and if) you run into a problem.