How to generate rows based on values in a column to fill missing values - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to generate rows based on values in a column to fill missing values (/thread-30669.html) |
How to generate rows based on values in a column to fill missing values - codesmatter - Oct-30-2020 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! RE: How to generate rows based on values in a column to fill missing values - Larz60+ - Oct-31-2020 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. |