Python Forum
How to generate rows based on values in a column to fill missing values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to generate rows based on values in a column to fill missing values
#1
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!
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 223 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Too much values to unpack actualpy 3 411 Feb-11-2024, 05:38 PM
Last Post: deanhystad
  Converting column of values into muliple columns of counts highland44 0 205 Feb-01-2024, 12:48 AM
Last Post: highland44
  __init__() got multiple values for argument 'schema' dawid294 4 1,896 Jan-03-2024, 09:42 AM
Last Post: buran
  How to access values returned from inquirer cspower 6 701 Dec-26-2023, 09:34 PM
Last Post: cspower
  partial functions before knowing the values mikisDeWitte 4 537 Dec-24-2023, 10:00 AM
Last Post: perfringo
  need to compare 2 values in a nested dictionary jss 2 798 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Copying the order of another list with identical values gohanhango 7 1,067 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Can I retrieve 2 values in a for ? Kakalok 3 484 Nov-06-2023, 10:35 PM
Last Post: menator01
  Search Excel File with a list of values huzzug 4 1,147 Nov-03-2023, 05:35 PM
Last Post: huzzug

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020