Group rows of 2nd Column by 1st Column using condition for length of string characters of text of the1st Column

Viewed 10

I have a dataframe with three Columns "Tasks, Instructions" and "len" (character length of Instructions).

I want to groupby the "Instructions" by "Tasks" and merge/concatenate the rows of "Instructions" for up to 100 characters of instructions per row in the "Tasks"

For Example:

d = {'Tasks': ["TaskOne","TaskOne","TaskTwo","TaskTwo"], 'Instructions': ["longTextofInstructionsforTask1", "longTextofInstructionsforTask1","longTextofInstructionsforTask2 additional text", "longTextofInstructionsforTask2 additional text"]}

df = pd.DataFrame(data=d)
CURRENT DATAFRAME

     Tasks                  Instructions                    len
0   TaskOne longTextofInstructionsforTask1                  30
1   TaskOne longTextofInstructionsforTask1                  30

2   TaskTwo longTextofInstructionsforTask2 additional text  46
3   TaskTwo longTextofInstructionsforTask2 additional text  46

DESIRED OUTCOME

     Tasks                  Instructions                                          len
0   TaskOne longTextofInstructionsforTask1 longTextofInstructionsforTask1         60
1   TaskTwo longTextofInstructionsforTask2 additional text longTextofInstructionsforTask2additional text                                                                              92
0 Answers
Related