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
  Replace values in Yaml file with value in dictionary PelleH 1 2,179 Feb-11-2025, 09:51 AM
Last Post: alexjordan
  Assigning cycle values in a list nmancini 3 1,007 Sep-16-2024, 09:35 PM
Last Post: deanhystad
  Append from csv to xlsx with values only Sick_Stigma 2 739 Aug-06-2024, 08:05 PM
Last Post: Sick_Stigma
  remove duplicates from dicts with list values wardancer84 27 5,822 May-27-2024, 04:54 PM
Last Post: wardancer84
Question Using Lists as Dictionary Values bfallert 8 2,306 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  Printing out incidence values for Class Object SquderDragon 3 1,263 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 2,009 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Too much values to unpack actualpy 3 1,501 Feb-11-2024, 05:38 PM
Last Post: deanhystad
  Converting column of values into muliple columns of counts highland44 0 907 Feb-01-2024, 12:48 AM
Last Post: highland44
  __init__() got multiple values for argument 'schema' dawid294 4 9,696 Jan-03-2024, 09:42 AM
Last Post: buran

Forum Jump:

User Panel Messages

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